-
Notifications
You must be signed in to change notification settings - Fork 401
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
The type javax.annotation.Nonnull cannot be resolved #2264
Conversation
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java
Show resolved
Hide resolved
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java
Outdated
Show resolved
Hide resolved
} | ||
IJavaProject javaProject = JavaCore.create(project); | ||
Map<String, String> options = javaProject.getOptions(true); | ||
assertEquals(options.get(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS), JavaCore.DISABLED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverse the arguments here. It's expected, actual.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
The changes LGTM, as for the test part, I suggest to add a test case not including jsr 305 in the pom (in any scope), and test this project would be imported successfully. e.g., sample project in redhat-developer/vscode-java#2712 (comment) |
@@ -2057,6 +2060,10 @@ private String getAnnotationType(IJavaProject javaProject, List<String> annotati | |||
if (classpathStorage.keySet().contains(annotationType)) { | |||
// for known types, check the classpath to achieve a better performance | |||
for (String classpath : result.classpaths) { | |||
IClasspathEntry classpathEntry = javaProject.getClasspathEntryFor(new Path(classpath)); | |||
if (isTest(classpathEntry, javaProject)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about directly use ClasspathOptions.scope = "runtime"
in https://github.com/eclipse/eclipse.jdt.ls/blob/f8452b422add64f9bbc80d0e22b48ed71797e563/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java#L2055
in this way, we can avoid checking classpath entry attribute here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. We could exclude test scope directly when getting the project classpaths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that using ClasspathOptions.scope = "runtime"
doesn't work in this case. I just tested sample project in redhat-developer/vscode-java#2712 (comment) and see the introduced artifact jsr 305 is in runtime scope:
So the scope filter won't filter this dependency. However, in the classpath entry, it has test attribute:
So the new introduced method isTest()
works. it will check the attributes of the classpath entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and I also tried ProjectCommand.isTestClasspathEntry()
mentioned by @jdneo , it also checks the attribute and it works well. So it seems that we don't need to add a new method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that using ClasspathOptions.scope = "runtime" doesn't work in this case. I just tested sample project in redhat-developer/vscode-java#2712 (comment) and see the introduced artifact jsr 305 is in runtime scope:
This is a bug on the utility method ProjectCommand.getClasspathsFromJavaProject
, which never uses the passed scope
parameter.
https://github.com/eclipse/eclipse.jdt.ls/blob/f8452b422add64f9bbc80d0e22b48ed71797e563/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/JavaLaunchConfigurationInfo.java#L35-L50
In the launch configuration template JAVA_APPLICATION_LAUNCH
, we could use the following attribute to exclude test code.
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_EXCLUDE_TEST_CODE" value="true"/>
The launch configuration dynamically returns the scope value.
https://github.com/eclipse/eclipse.jdt.ls/blob/f8452b422add64f9bbc80d0e22b48ed71797e563/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/JavaApplicationLaunchConfiguration.java#L45
If the resolve logic doesn't filter the test scope directly, then it's a bug of JavaLaunchDelegate.getClasspathAndModulepath
that doesn't handle the test scope well.
I'm OK to filter it on jdt.ls side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's interesting that the test attribute is set to true
but the maven.scope
is runtime
.
Is that a bug of m2e?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which never uses the passed scope parameter.
It will,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI the jsr305 dependency is declared as implementation
scope, not test
in spring-kafka: https://github.com/spring-projects/spring-kafka/blob/4bcb503a2fb33d20b45f4cc241c769c397bf0a7d/build.gradle#L173
it seems that jsr305 introduced by maybe we can check the classpath attribute As for Gradle projects, directly use |
It is intentional. See https://github.com/eclipse-m2e/m2e-core/blob/master/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/DefaultClasspathManagerDelegate.java#L164 |
The https://github.com/yotov/vscode-nullable project includes jsr 305 indirectly. It is the same as the maven/null-analysis. |
@rgrunber @CsCherrYY @jdneo @testforstephen I have updated the PR. |
Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
maven recognizes it as runtime
|
that's what I found and suggested in #2264 (comment), if all the runtime classpath entries have
You're right. I just misunderstood that the project doesn't have jsr 305 dependency. |
Yeah intuitively it made sense to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ready to be merged.
Fixes redhat-developer/vscode-java#2712
Fixes redhat-developer/vscode-java#2721
Fixes redhat-developer/vscode-java#2725
Signed-off-by: Snjezana Peco snjezana.peco@redhat.com