eclipse-jdt / eclipse-jdt/eclipse.jdt.core
Error shown after project clean which goes away when editing the class file
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
**Minimal example:**
*Util.java*:
```
package com.test;
import java.util.concurrent.Callable;
public class Util
{
public static V nullInCaseOfError (final Callable callable)
{
try {
return callable.call();
} catch (final Exception exception) {
return null;
}
}
}
```
*B.java*:
```
package com.test;
public final class B
{
public static final Class CLASS = Util.nullInCaseOfError(() -> Class.forName("does.not.Matter"));
}
```
*A.java*:
```
package com.test;
import java.lang.reflect.Constructor;
import java.lang.Class;
public final class A
{
public static final Class CLASS = null;
public static final Constructor CONSTRUCTOR = Util.nullInCaseOfError(() -> CLASS.getConstructor(B.CLASS)); // <- Error
}
```
After *Project -> Clean...* in class *A* the commented line shows an error marker saying:
`Type mismatch: cannot convert from Constructor to Constructor `
This error goes away if the file is edited and saved (e.g. add a space, delete it and save the file).
**Notes:**
* The code in this minimal example is not running and doesn't make much sense but shows the problem
* This is not new (I was just too lazy to create a minimal working example from a big project)
* The error never shows up if class *A* is renamed to *C* (ordering problem?)
* In class *B* if I write just `public static final Class CLASS = null` the error also is not happening (seems to be related to the Lambda function used to catch exceptions)
* My real project is a Maven project. There the error is shown after a restart and after *Maven -> Update Project...* (and the only way I found so far to resolve that is to edit and save the Java class file)
**Eclipse version:**
Version: 2022-06 (4.24.0)
Build id: 20220609-1112
Contributor guide
Assessment
This issue has not been assessed yet.