vscode-java: The type javax.annotation.Nonnull cannot be resolved
In one of my projects, I’m getting an error after upgrading to the latest version:
The type javax.annotation.Nonnull cannot be resolved. It is indirectly referenced from required .class filesJava(16777540)
Annotation type 'javax.annotation.Nonnull' cannot be found on the build path, which is implicitly needed for null analysisJava(536871894)
I saw the changelog and found that the issue relates to enhancement - Enable annotation-based null analysis. See #1693.
Removing “javax.annotation.Nonnull” from “java.compile.nullAnalysis.nonnull” config fixes the problem for me.
Environment
- Operating System: MacOS 12.6
- JDK version: openjdk 17 2021-09-14
- Visual Studio Code version: 1.71.2
- Java extension version: 1.11.0
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 8
- Comments: 16 (9 by maintainers)
You should be able to disable this feature with the following settings (on the individual workspace, or globally).
.vscode/settings.json
@yotov thank-you. Am able to reproduce.
Looking at the classpath of the project, I see both
com.google.code.findbugs:jsr305:jar:3.0.2:runtime
&org.springframework:spring-core:jar:5.3.22:compile
. So basically we have 2 annotation providers on the classpath. It looks like the defaults prefer thejsr305
provides (eg. javax.annotation…) over the spring framework provider (eg. org.springframework.lang…). However clearly in this case it should be reversed.Can you try, the following setting ? It’s basically just the default settings, but the spring framework annotations are moved to the top.
.vscode/settings.json
@chowethan @yotov Could you try to remove .project, .classpath, .settings from your project?
@jvansant The fix https://github.com/eclipse/eclipse.jdt.ls/pull/2264 is available in the newest pre-release verison
1.12.2022101204
, you can try to switch to this version to see if it works.@rgrunber here is a sample project that causes the problem for me - https://github.com/yotov/vscode-nullable I managed to find that I get this error in projects that use namedParameterJdbcTemplate.batchUpdate and having a spring-kafka in dependencies. Removing the line with batchUpdate fixes the error. Removing the spring-kafka dependency also fixes the error.
Hope that this can help you 😃
I have setup my settings.json file as instructed (I chose the workspace root .vscode directory)
However, I’m still seeing the same error after running
mvn clean install
as well as the extension commandJava: Clean Java Language Server Workspace
Does this have anything to do with the issue mentioned above?