Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internal compiler error: Classcast exception

I am getting below error at the start of java file right at letter 'p' of package

Internal compiler error: java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.lookup.MethodBinding cannot be cast to org.eclipse.jdt.internal.compiler.lookup.FieldBinding at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:817)

Project compiles fine from command prompt. but eclipse is showing this error.I am using jdk 8. any help is highly appreciated

I tried restarting eclipse, cleaning project, installing different versions of eclipse etc.

like image 944
user837593 Avatar asked May 16 '19 19:05

user837593


People also ask

How do you fix ClassCastException?

To prevent the ClassCastException exception, one should be careful when casting objects to a specific class or interface and ensure that the target type is a child of the source type, and that the actual object is an instance of that type.

What causes ClassCastException?

ClassCastException is a runtime exception raised in Java when we try to improperly cast a class from one type to another. It's thrown to indicate that the code has attempted to cast an object to a related class, but of which it is not an instance.

Is ClassCastException checked?

ClassCastException is one of the unchecked exception in Java. It can occur in our program when we tried to convert an object of one class type into an object of another class type.

How do you get ClassCastException?

ClassCast Exception is thrown when we try to cast an object of the parent class to the child class object. However, it can also be thrown when we try to convert the objects of two individual classes that don't have any relationship between them.


2 Answers

I noticed that in my workspace the error only occurs with the classes containing the annotation @JsonProperty. The workaround that I found - comment all these annotations in the class out, save and let the workspace build run. Then uncomment and save, so that the class file returns to its original state. In my case the error disappears until Eclipse compiles the class again. Normally it wouldn't happen as long as the class is not changed.

like image 116
Michael Spiro Avatar answered Sep 21 '22 09:09

Michael Spiro


I had a similar issue. It turned out to be a compatibility issue between Lombok 1.18.8 and Eclipse 4.11. I reverted to Lombok 1.18.2 to get it working again. The Eclipse ticket that was closed recommends using Lombok 1.16.18. https://bugs.eclipse.org/bugs/show_bug.cgi?id=547244

like image 43
dansomething Avatar answered Sep 22 '22 09:09

dansomething