Java: Unresolved compilation problem

Viewed 256926

What are the possible causes of a "java.lang.Error: Unresolved compilation problem"?

Additional information:

I have seen this after copying a set of updated JAR files from a build on top of the existing JARs and restarting the application. The JARs are built using a Maven build process.

I would expect to see LinkageErrors or ClassNotFound errors if interfaces changed. The above error hints at some lower level problem.

A clean rebuild and redeployment fixed the problem. Could this error indicate a corrupted JAR?

10 Answers

(rewritten 2015-07-28)

The default behavior of Eclipse when compiling code with errors in it, is to generate byte code throwing the exception you see, allowing the program to be run. This is possible as Eclipse uses its own built-in compiler, instead of javac from the JDK which Apache Maven uses, and which fails the compilation completely for errors. If you use Eclipse on a Maven project which you are also working with using the command line mvn command, this may happen.

The cure is to fix the errors and recompile, before running again.

The setting is marked with a red box in this screendump:

Eclipse Preferences under OS X

try to clean the eclipse project

  1. Just try to include package name in eclipse in case if you forgot it
  2. Import all packages before using it, EX: import java.util.Scanner before using Scanner class.
  3. These improvements might work and it will not give Java: Unresolved compilation problem anymore.
  4. Also make sure to check compiler compliance level and selected jdk version is same

As a weird case, I encountered such an exception where the exception message (unresolved compilation bla bla) was hardcoded inside of generated class' itself. Decompiling the class revealed this.

I had the same issue using the visual studio Code. The root cause was backup java file was left in the same directory.

Removed the backup java file When the build failed, selected the Fix it, it cleaned up the cache and restarted the workSpace.

Related