Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eclipse editor falsely flags error when using 'proceed()' in lambda expression #5

Open
kriegaex opened this issue Sep 16, 2021 · 0 comments

Comments

@kriegaex
Copy link
Contributor

kriegaex commented Sep 16, 2021

I am not sure if anyone still looks at AJDT Bugzilla, so I am recording this problem here, creating tracker bug #576017 in AJDT Bugzilla only.

While answering StackOverflow #69196740, I noticed the following problem in AJDT.

This aspect compiles and runs fine in Eclipse 2021-06 and AspectJ 1.9.7:

package de.scrum_master.aspect;

import java.util.concurrent.Callable;

public aspect MemoizeAspect {
  Object around(): execution(* doesNotExist()) {
    MyCache<String, Object> cache = new MyCache<>();
    return cache.get("key", () -> proceed());
  }

  Object around(): execution(* doesNotExist()) {
    MyCache<String, Object> cache = new MyCache<>();
    Callable<?> callable = () -> proceed();
    return cache.get("key", callable);
  }

  Object around(): execution(* doesNotExist()) {
    MyCache<String, Object> cache = new MyCache<>();
    return cache.get("key", () -> "value");
  }

  public static class MyCache<K, V> {
    public V get(K key, Callable<? extends V> loader) {
      return null;
    }
  }
}

Eclipse does not show any errors in the "Problems" view. But the editor falsely flags an alleged error:

image

The error message is:

The method get(String, Callable<? extends Object>) in the type MemoizeAspect.MyCache<String,Object> is not applicable for the arguments (String, () -> {})

image

Please note:

  • As you can see in the third around-advice, when returning a fixed value instead of proceed() or proceed(arg1, args2) there is no problem.
  • When transforming the aspect into annotation-style, it also works. But in that case, we also need to wrap proceed() into a try-catch block handling Throwable, so the source code looks different.
  • Factoring out the Callable into a local variable like in the second around-advice works, too.
@kriegaex kriegaex transferred this issue from eclipse-aspectj/aspectj Mar 21, 2022
@kriegaex kriegaex changed the title [AJDT] Eclipse editor falsely flags error when using 'proceed()' in lambda expression Eclipse editor falsely flags error when using 'proceed()' in lambda expression Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant