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

"Type mismatch" regression since 4.29 with generics and null-analysis #3461

Open
chrtmn opened this issue Dec 16, 2024 · 1 comment
Open
Assignees
Labels
bug Something isn't working null Issues related to null pointer analysis regression Something was broken by a previous change

Comments

@chrtmn
Copy link

chrtmn commented Dec 16, 2024

After updating to a new ecj version (4.34), I got a new compiler error that did not occur with the old version or with javac. I traced the new behavior back to ecj version 4.29. There was no error with version 4.28. Further tests revealed that it only occurs when the null analysis is activated. If you deactivate it, the error disappears. The issue was found while using Eclipselink. Below, I have extracted the necessary types into an example.

1. ERROR in ErrorClass.java (at line 3)
        @AnnotationWithClassType(ImplementationClass.class)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^
Type mismatch: cannot convert from Class<ImplementationClass> to Class<? extends AbstractClassInAnnotation>

works:

java -jar ecj-4.28.jar -17 -warn:+nullAnnot *.java
java -jar ecj-4.34.jar -17 -warn:-nullAnnot *.java

error:

java -jar ecj-4.29.jar -17 -warn:+nullAnnot *.java
java -jar ecj-4.34.jar -17 -warn:+nullAnnot *.java

Perhaps it is related to #2941?

AbstractClassInAnnotation.java

// real world: https://github.com/eclipse-ee4j/eclipselink/blob/4.0/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/descriptors/ClassExtractor.java
public abstract class AbstractClassInAnnotation { }

AnnotationWithClassType.java

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

// real world: https://github.com/eclipse-ee4j/eclipselink/blob/4.0/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/annotations/ClassExtractor.java
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface AnnotationWithClassType {
            Class<? extends AbstractClassInAnnotation> value();
}

AnotherType.java

// completely independent type, referenced in ErrorClass
class AnotherType { }

ImplementationClass.java

 // used as type parameter in ErrorClass
public final class ImplementationClass extends AbstractClassInAnnotation { }

ErrorClass.java

// since ECJ 4.29: "Error: Type mismatch: cannot convert from Class<ImplementationClass> to Class<? extends AbstractClassInAnnotation>"
@AnnotationWithClassType(ImplementationClass.class)
abstract class ErrorClass<A extends AnotherType> { // notice: removing "<A extends AnotherType>" makes the error also disappear
}
@jukzi jukzi added null Issues related to null pointer analysis regression Something was broken by a previous change bug Something isn't working labels Dec 16, 2024
@jukzi
Copy link
Contributor

jukzi commented Dec 16, 2024

cc @stephan-herrmann because null was mentioned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working null Issues related to null pointer analysis regression Something was broken by a previous change
Projects
None yet
Development

No branches or pull requests

4 participants