javax.annotations cannot find symbol

已回答

All of a sudden, Intellij (version 2018.1.5, Linux)  says it cannot find symbol for classes in javax.annotation (e.g. javax.annotation.Nullable). On screen it shows as if it compiles neatly, but when attempting to run a test or to 'Build project' it says: cannot find symbol. The package is definitely on the classpath and everything goes well when I do a mvn build on the command line. 

The jar that holds the classes (/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar) is found in my External libraries.

A colleague of mine experiences the same issue (he has got 2018.4 on Windows)

Should I report a bug somewhere?

Thanks for any help,
Steven

6

If you can reproduce the issue with the isolated sample project, please file a bug at https://youtrack.jetbrains.com/issues/IDEA and attach the project there.

0
Avatar
Permanently deleted user

Im experiencing the same symptoms; 

IntelliJ IDEA 2018.1.4 (Ultimate Edition)
Build #IU-181.5087.20, built on May 17, 2018
Licensed to Robert Malai
Subscription is active until January 8, 2019
JRE: 1.8.0_152-release-1136-b39 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.12.6

 

I'm trying to compile with Java 10, inside the IDE (for tests). Works with maven, fails with IDE. Any suggestion? 

0

Please report a bug with the logs/sample project. Thank you.

0
Avatar
Permanently deleted user

I found that when you delete your local repo altogether and clone it again and then start with a 'Build project' from the menu (Ctrl-F9) before you run any tests in the IDE, the problem is gone for some time. But -at least in my case- it does come back unexpectedly.

0
Avatar
Permanently deleted user

I've got the same issue. Suddenly IntelliJ cannot run my test because it cannot find `java.notation.Nullable`

However the editor does not show the compilation error and maven builds without issue. It happened suddenly. This means I cannot run tests from IntelliJ and it's very frustrating.

0
Avatar
Permanently deleted user

OK I manage to get it to work by hitting Build > Rebuild Project

However Build > Build Project did not work

Edit:

Actually this does not work all the time. I'm having the same problem this morning and cannot fix it this way

0

Please provide sample project to check. What JDK version do you use?

0
Avatar
Permanently deleted user

I can't really do that, I'm having this issue on a large project. Plus it's very intermittent.

I'm running IDEA on JDK10 and compiling on JDK10.

0

Do you use Java 9 modules system?

If you run IDE under Java 10, please switch to the bundled 1.8 JDK, which is recommended JDK version, please see https://intellij-support.jetbrains.com/hc/en-us/articles/206544879.

0
Avatar
Permanently deleted user

Hello everyone. 

I had this error with Intellij 2018.1.6 (Java 10 project, IDE launched with bundled 1.8 JDK).

I have just upgraded to 2018.2 and it solves the problem !

1
Avatar
Permanently deleted user

Hi Jetbrains support.

Is there a solution for this yet?

 

I cannot run tests from within IntelliJ due to the exact same error as the OP: "cannot find symbol for classes in javax.annotation (e.g. javax.annotation.Nullable)"

Using IntelliJ Ultimate 2018.2.5 with  Boot Bundled JDK...1.8.0_152-b19 (\JetBrains\IntelliJ IDEA 2018.2.4\jre64)

Best,

Martin

 

0

Hello Martin,

Could you please provide sample project example?

 

0
Avatar
Permanently deleted user

Hi Yaroslav

Before I do the work of trying to isolate this problem into a sample project, could you please clarify for me whether this issue has been answered, and what the answer is? The issue is marked as answered at the top...

Thanks,

Martin

0

Martin,

"answered" mark means that issue is checked by support team to avoid double checking. There was similar issue on YouTrack, but it was closed as "Can't reporduce" due missing project sample.

 

0
Avatar
Permanently deleted user

Also Yaroslav, there is a guy sitting next to me with the exact same project open with the exact same version of Intellij (though not Ulimate) and he can run the tests without getting the "cannot find symbol for classes in javax.annotation (e.g. javax.annotation.Nullable)" error...

So not sure it would be possible to isolate this in a simple project...

 

0
Avatar
Permanently deleted user

I think it goes beyond what is in the project itself.

We also noticed that certain modules/sub projects in the project allow testing against javax.annotation.Nullable and certain don't.. so we have had to keep all our annotations in one module..

But then sometimes all the testing fails.. and no javax.annotations can be found ...

 

Same problem on "Rebuild". It compiles fine, but can't Rebuild/Test

 

0
Avatar
Permanently deleted user

By the way Yaroslav, the javax.annotations are all being generated by Immutables (https://immutables.github.io/) so they are in "generated sources root" folders - does that make any difference?

0

Martin,

Does "File | Invalidate Caches" help? Do you use any build system (Maven, Gradle)?

 

0
Avatar
Permanently deleted user

 

It is a Gradle project. So first the Immutables code with the javax.annotations is generated using Gradle, and then the IntelliJ tests/rebuild fails..

 

0

Martin,

It would be great if you could provide sample project example, so developers could check it.

0
Avatar
Permanently deleted user

Hi Yaroslav

I deleted the project and Git repository and then recreated them. The problem has gone away for now.

Next time I will try "File | Invalidate Caches".

If I ever get time (I doubt it), I will try to make a sample project that isolates this issue - although as we have seen, the problem is intermittent and depends on some stored state... 

Thanks,

Martin

0

Martin,

Thanks for information! At least running "Invalidate Caches" results will give us some more data about the issue.

0
Avatar
Permanently deleted user

Thanks Yaroslav

0
Avatar
Permanently deleted user

I'm having the same issue with Maven for tapestry annotations:

Error:(30, 18) java: cannot find symbol
symbol: method module()
location: @interface org.apache.tapestry5.annotations.Import

I'm running on IntelliJ Ultimate 2018.3.5 and I've already tried invalidating the caches (and restarting), building, rebuilding, mvn clean, ...

This happened after I've changed some dependencies, however the maven build (mvn clean install) and jetty run (mvn jetty:run) works fine, which means that it must be an IDE's fault.

I'd be happy about any solution that doesn't involve deleting the whole project or anything like that.

0

Try to delete .idea directory and reimport the project from pom.xml, make sure all the dependencies are detected, check https://stackoverflow.com/a/42427510/104891 for the diagnostics. If nothing helps, report a bug with the sample project as suggested in the first comment.

0
Avatar
Permanently deleted user

Deleting .idea seems to have done the trick, it's rather annoying to setup the environment again though. I can't provide an example project, as my current project isn't public and I don't know what causes this problem.

0

You can backup/restore run/debug configurations so that you don't have to set them up again, see https://stackoverflow.com/a/3136255/104891.

0
Avatar
Permanently deleted user

We've had the same issue both on 2018.2 and 2019.1, under Fedora 28 and the newest Xubuntu respectively. Deleting .idea and reimporting the project helps, but this issue is annoying nevertheless.

0

This is the fix:

```
  <dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifact Id>
    <version>1.2</version>
  </dependency>
```

1

After searching it, I guess the difference between JDK EE and SE may cause the problem. Ref: https://bugs.openjdk.java.net/browse/JDK-8152931 https://bugs.openjdk.java.net/browse/JDK-8152842 

 Solution: 1. rename javax.annotation-api-1.2.jar to java.annotations.common-1.2.jar and deploy it on the upgrade module path as an automatic module (e.g. -upgrademodulepath java.annotations.common-1.2.jar);

2. just install dependency via maven.

0

请先登录再写评论。