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

-Astubs doesn't write type arguments for outer class when inner class present #3438

Closed
jwaataja opened this issue Jul 7, 2020 · 0 comments · Fixed by #3441
Closed

-Astubs doesn't write type arguments for outer class when inner class present #3438

jwaataja opened this issue Jul 7, 2020 · 0 comments · Fixed by #3441

Comments

@jwaataja
Copy link
Contributor

jwaataja commented Jul 7, 2020

When using -Ainfer=stubs, creating stub files for classes with inner classes fails to include type arguments in the outer class. Consider this class

public class GenericClass<T> {
    public class InnerClass {
        // Create error to force generation of stub file, ignore.
        Object o = null;
    }
}

I compiled it with,

$CHECKERFRAMEWORK/checker/bin/javac -processor NullnessChecker -Ainfer=stubs GenericClass.java

When I inspect the generated stub file, I see

import org.checkerframework.checker.initialization.qual.Initialized;
import org.checkerframework.checker.nullness.qual.Nullable;

class GenericClass {

  class InnerClass {

    // fields:

    @Initialized @Nullable java.lang.Object o;

  }
}

Notice that GenericClass has no type parameter.

When I try to use this stub file, I get an error:

$CHECKERFRAMEWORK/checker/bin/javac -processor NullnessChecker -Astubs=build GenericClass.java
warning: StubParser: annotateTypeParameters: mismatched sizes:  typeParameters (size 0)=[];  typeArguments (size 1)=[T extends Object];  decl=class GenericClass {      class InnerClass {          @Initialized         @Nullable         java.lang.Object o;     } };  elt=GenericClass (class com.sun.tools.javac.code.Symbol$ClassSymbol).; for more details, run with -AstubDebug
GenericClass.java:4: error: [assignment.type.incompatible] incompatible types in assignment.
        Object o = null;
                   ^
  found   : null
  required: @Initialized @NonNull Object
1 error
1 warning

Output for

$CHECKERFRAMEWORK/checker/bin/javac -processor NullnessChecker -Ainfer=stubs GenericClass.java -version -verbose -AprintAllQualifiers

javac_create_stubs_output.txt

Output for

$CHECKERFRAMEWORK/checker/bin/javac -processor NullnessChecker -Astubs=build GenericClass.java -version -verbose -AprintAllQualifiers

javac_use_stubs_output.txt

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

Successfully merging a pull request may close this issue.

1 participant