question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The type javax.annotation.Nonnull cannot be resolved

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:8
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
rgrunbercommented, Oct 5, 2022

You should be able to disable this feature with the following settings (on the individual workspace, or globally).

.vscode/settings.json

{
    "java.compile.nullAnalysis.nonnull": [
    ],
    "java.compile.nullAnalysis.nullable": [
    ]
}
2reactions
rgrunbercommented, Oct 6, 2022

@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 the jsr305 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

{
	"java.compile.nullAnalysis.nullable": [
		"org.springframework.lang.Nullable",
		"javax.annotation.Nullable",
		"org.eclipse.jdt.annotation.Nullable"
	],
	"java.compile.nullAnalysis.nonnull": [
		"org.springframework.lang.NonNull",
		"javax.annotation.Nonnull",
		"org.eclipse.jdt.annotation.NonNull"
	]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't find @Nullable inside javax.annotation.* - Stack Overflow
Unable to import javax.annotation.Nullable; I have jsr250-api-1.0.jar in my classpath. I even tried updating maven pom <dependency> ...
Read more >
The annotation Nonull cannot be resolved to a type - SpigotMC
Tried to import javax.annotation.Nonnull, but it tells me that javax.anotation doesn't contain Nonull, tried to add the dependency to ...
Read more >
javax.annotation.Nullable cannot be found by IDEA - YouTrack
The only one known workaround is to type imports manually (after adding 'import javax.annotation.Nullable' everything is fine for current class).
Read more >
Full Text Bug Listing - Bugs - Eclipse
annotation.Nullable Object) Now we have an URB(javax.annotation.Nullable) Later when trying to resolve the import javax.annotation.Nullable, we find the URB, ...
Read more >
how to fix Cannot resolve symbol 'Nullable' - YouTube
Java annotations are pieces of metadata that provide information about the code they are used with, and can instruct the IDE how to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found