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

Error with UnderInitialization #3485

Closed
jpschewe opened this issue Jul 20, 2020 · 2 comments
Closed

Error with UnderInitialization #3485

jpschewe opened this issue Jul 20, 2020 · 2 comments

Comments

@jpschewe
Copy link

I have a class method that finishes initialization outside of the constructor. I'm using framework version 3.5.0 through the gradle plugin version 0.5.5.

The test case is attached.
checker-bugs.zip
It consists of a build.gradle file and a class that uses the "@UnderInitialization" annotation to specify that this method is expected to be called while the object is being initialized.

The error that I get when building is below. I believe that the "found" reporting is incorrect as I have specified "UnderinitializationBug.class" in the annotation.
If I change the class inside the annotation to be "Object.class", then the code compiles. This suggests that the reporting is backwards. "found" should say "UnderInitializationBug.class" and "required" should say "Object.class".

>./gradlew classes
> Task :createCheckerFrameworkManifest

> Task :compileJava FAILED
/home/jpschewe/projects/checker-bugs/src/main/java/net/mtu/eggplant/checker-bugs/UnderInitializationBug.java:8: error: [method.invocation.invalid] call to finishInit() not allowed on the given receiver.
    finishInit();
              ^
  found   : @UnderInitialization(java.lang.Object.class) @NonNull UnderInitializationBug
  required: @UnderInitialization(UnderInitializationBug.class) @NonNull UnderInitializationBug
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
2 actionable tasks: 2 executed
@wmdietl
Copy link
Member

wmdietl commented Jul 20, 2020

The error message is correct.
At the call site of finishInit(); the UnderInitializationBug instance has called the super constructor, so is initialized up-to j.l.Object. So the "found" receiver is @UnderInitialization(java.lang.Object.class) @NonNull UnderInitializationBug.
The declaration of method finishInit requires an @UnderInitialization(UnderInitializationBug.class) @NonNull UnderInitializationBug receiver, so the found vs. expected error message is correct.
When you change the declaration of finishInit to require a @UnderInitialization(java.lang.Object.class) the found and expected types match.
Does this make sense now?

@jpschewe
Copy link
Author

OK, I misread the message. "required" is what I specified and "found" is the type that was found during analysis. And the argument to UnderInitialization specifies the class that is known to be initialized.

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

2 participants