Module compiles, but editor shows compilation issues

Answered

Since I reorganized my environment today (New project, clean checkout of code from SVN), I have not been able to edit code without the editor showing 'compilation issues' for code that does actually compile.

I have a bunch of Maven modules that compile file using Maven (both from command line and from IDEA) and compilation from IDEA (Build -> Compile/Make) works as well.
But when opening one of the java files, all referenced types that do not originate from my Maven module itself (types from dependencies) are marked as compilation problems ('Cannot resolve symbol XYZ') in the editor. Code completion only reveals types from dependencies when I type the fully qualified name, but a type entered this way is still displayed as a compilation problem (red).

I have no clue what is going wrong here. Has any encountered this behaviour before? I am using IDEA 13.1.1.

24 comments
Comment actions Permalink

Try invalidating your caches and restarting IDEA (File > Invalidate Cache). Wait for IDEA to re-index your project (Status indicator on lower right status bar). The caches will sometimes become corrupted. This is most likely to occur upon reorganizing a project as you mentioned you did.

4
Comment actions Permalink

That solves my issue! Thank you very much!

0
Comment actions Permalink

Hello, 

 

I have the same kind of problem.

The module is compiling with success. But the editor shows me red errors for the objects referreing to a transitive maven dependency of my module.

For example Spring and hibernate are used in my code, but the dependency to spring and hibernate is transitive.

I tried the invalidate caches solution, but it doesn't resolve my problem.

Could you please help?

Thxs, 

Fatma.

4
Comment actions Permalink

Same issue. Couldn’t be solved by invalidate caches solution. Any other solution?

0
Comment actions Permalink

Ankitraj0007 The problem was actual 6 years ago. Not sure you faced the same issue. So, please create separate thread and describe your project structure. 

As a general troubleshooting step, you can re-import the project after removing .idea directory from the project's root. 

0
Comment actions Permalink

I have been using from past 3 years, currently using IntelliJ 2020.3.3 version for java spring + gradle. I continue to face issues even after cache invalidation. The IDE resolves the editor compilation issues after few cache invalidations attempts. However, often gets stuck with 'indexing' files during this process as well. I also use JDK indexed files as suggested by the IDE for better performance. My friends often face same issue.

1
Comment actions Permalink

Srini Try EAP version of IntelliJ IDEA where some indexing-related improvements were done. 

0
Comment actions Permalink

Hi, I also faced this issue a moment ago with: IntelliJ IDEA 2021.1 (Ultimate Edition) Build #IU-211.6693.111, built on April 6, 2021

Build was ok on command line and also via IDE "Buid project" button, but editor was not able to import a class from the same project.

When pressing Ctrl+Space then instead of importing the class, it inserted full package path and even after still stayed red.

"Invalidate caches" did fortunately help.

 

1
Comment actions Permalink

Hi,

I have the same issue as Markov, with exactly the same IntelliJ build (IntelliJ IDEA 2021.1 (Ultimate Edition), Build #IU-211.6693.111, built on April 6, 2021). It happened as well in earlier versions, but I'm fed up with invalidating caches over and over again. It started with a locally installed Maven dependency (from an internal project, installed from other instance of IntelliJ) that stopped being recognized. Then I bumped its version to the latest snapshot in pom.xml, re-imported project from "pom.xml > Dependency Analyzer > Reimport", but it still didn't help. Yet, "Build > Build Project" worked just fine, building from Maven worked just fine, but editors for some classes that used this dependency - were showing lots of errors. I have just tried "Reload All Maven Projects" from Maven view - and this time it helped, but recently I have run into cases that only invalidating cache option worked. Perhaps you should add it to some "everyday user routine" documentation to invalidate caches before end of the day? (yes, this is becoming extremely frustrating!)

Tomasz

0
Comment actions Permalink

A lot of index- and cache-related issues were fixed in 2021.1.1 EAP, please try it: https://confluence.jetbrains.com/display/IDEADEV/IDEA+2021.1+latest+builds

0
Comment actions Permalink

Konstantin Annikov thanks, I'm testing it since yesterday, and will let you know if the problem occurs again.

0
Comment actions Permalink

Konstantin Annikov it hasn't taken long and today I run into problems again. This time after pulling some changes from the Git repo - "Build > Build project" started to output errors related to missing "com.fasterxml.jackson.annotation" package, but the editor showed no errors and Maven build was successful, too (see below for a screenshot), I could also navigate to classes that could not be seen by the build. Then I tried re-importing Maven projects, but it got worse and out of a sudden - some other problems started to be reported (there were no changes in source code, no pulling, etc.). Then I headed to "new IntelliJ daily routine task" and used "File > Invalidate caches" (file system cache + local history + shared indexes). Surprisingly - it did not help this time and editors started to show the errors about FasterXML packages missing here and there. So I deleted ".m2/repository/com/fasterxml" folder, re-imported Maven projects, used Maven to build most of them (in order required for the final project that relied on the others) - and only then "Build > Build project" was successful and I could run it from IntelliJ for testing purposes.

If it was about some fancy feature that is something totally marginal and optional - then I would not care much, but when such a core feature is totally messed up (in previous versions it happened rather rarely) and taking so much time to finally get it working - then I'm really starting to look for something else not blown with some "Code with me" fancy features, but a tool that simply works and lets me get my job done.

1
Comment actions Permalink

I'm sorry for the issues.

>"Build > Build project" started to output errors related to missing "com.fasterxml.jackson.annotation" package, but the editor showed no errors and Maven build was successful, too (see below for a screenshot),

If Maven build works, this sounds like https://youtrack.jetbrains.com/issue/IDEA-266634 But it was fixed in 2021.1.1 Preview version. So must be a different problem. Have you noticed were there any error with the Maven sync?

To investigate this if it still happens to you could you please (at the moment when issue occurs) provide the project project configuration files zipped (.idea project configuration sub-folder and module's .iml files) and IDE logs zipped (Help | Collect Logs and Diagnostic Data action) after reproducing the build problem with build log debugging enabled (please see IntelliJ IDEA External Build logs section here https://intellij-support.jetbrains.com/hc/en-us/articles/207241085 ). Please also provide IDE system/external_build_system/ directory zipped.

For uploading, you can use https://uploads.jetbrains.com or any file sharing service.

0
Comment actions Permalink

Just piping in to say I have the same problem I think, or a related one so I should  post here. 

 

Project compiles OK. One Java file is red all over with "cannot resolve symbol" error. The Java file is  looking for is a sibling in the same folder. 

Neither file has a package statement (or equivalently has the default package) on account of the fact that both .java files were created by another program and that program deposits the .java files it writes without attempting to figure out the full enclosing context of package  names (that is how this program works) it is executed in.

 

I can understand the red errors since they are in  a package, X, but don't declare that fact. Nevertheless, everything compiles. 

 

( I should add that there is no chance the compiler is encountering a previous .class compilation of this file in the classpath a fact I proved by altering the source file, doing a clean--->build then decompiling the resultant .class file which was just compiled from the altered source. When I do that, I see my alteration, thus proving the .class file is the result of compiling the very red Java file. )

 

I cleared my caches (goodbye local history) but it still behaves the same. 

 

In my mind  this means I have the wrong model for what the compiler is doing. It *ought* to see the bad  (default) package name in this Java file and choke, but it doesn't for some reason.

 

I am going to guess, without attempting to prove, that that is down to the fact the Java file in question is in the default  package as is its "missing" sibling and somehow that makes it all legal under Java's rules of compilation but if that's the case, I would have gotten it wrong on a test. 

 

So it's **not** that the Java file is red per se that is confusing me, it's that it compiles just fine and produces the correct output that is confusing me. 

0
Comment actions Permalink

It is the same for me. . . I 've had enough . . . I am trying eclipse . . .

0
Comment actions Permalink

The problem for me was the jars were corrupted.  Once I deleted them and reloaded them, it worked fine. . . 

1
Comment actions Permalink

I have the same problem... And this isn't the first time... it's so frustrating.
I already download eclipse, but I really like Intelji, how can you release a new version with such a huge bug with the main feature?

All of my dependencies from spring and hibernate are red, and the application runs fine..
Using Invalidate caches did not help, reloading Gradle didn't help.

0
Comment actions Permalink

Rana zaied

Try the following:

  1. Close your project window (and IntelliJ)
  2. Remove all *.iml files and the .idea folder from the project's root directory.
  3. Re-import the project into IntelliJ from existing sources.

You can also try deleting the IDEA system directory altogether, then re-importing your project.

If the problem remains, please temporarily disable all downloaded plugins, delete the log directory, restart the IDE, reproduce the problem and provide the logs generated by Help | Collect Logs and Diagnostic Data.

0
Comment actions Permalink

Given:

- Ubuntu 20.04;
- multi-module Kotlin project in IntelliJ Ultimate 2021.2.2. No issues at this point. 

Action:
- Open another window with another  multi-module Kotlin project.

Result: 
- Unresolved references appears in every active or visited Kotlin tab. 
- This continues in the first  IntelliJ instance after another instance has been closed.
- IDE restart doesn't solve this issue. 
- "Invalidate and restart ..." does temporary fix this problem but in this case IDE might again start getting "red worms" even without opening of a second window. Usually I just restart Ubuntu. 

So while there is a workaround it is an inconvenience.

Since we already know that  modal windows are shared between the running IDE instances looks like the caches also might have shared regions. 

0
Comment actions Permalink

Skupcl

Please submit a new bug report to our issue tracker about this, and attach your idea.log file to it (Help | Show Log in...).

You can reduce the attachment's visibility to jetbrains-team to make it private.

0
Comment actions Permalink

I had similar issues, what worked for me was to exit the IDE and delete in my local maven repository those dependencies for which the classes always turned red. Then back into the IDE and reload the project, it fetches anew the dependencies and all was fine again.

This does not require invalidating the global cache - which is extremely disruptive as it clears the local history. Not sure why this is always touted as the first solution to everything.

1
Comment actions Permalink

Having the same issue as of now, though we entered in 2022. Anyone caring to fix this issue?

0
Comment actions Permalink

@Serge Baranov Thanks for the prompt response. I submitted the bug report.

0

Please sign in to leave a comment.