Skip to content

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

@kriegaex

Description

@kriegaex

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions