13

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.

user837593
  • 337
  • 1
  • 5
  • 25
  • 2
    Can you please show the code, specific JVM version, Eclipse version, and OS? – WJS May 16 '19 at 19:25
  • you are using `ecj` compiler in eclipse which is `!=` from command line. – Eugene May 16 '19 at 19:25
  • 1
    Sounds like a bug in the eclipse compiler. File a report? – Thorbjørn Ravn Andersen May 16 '19 at 19:26
  • @ThorbjørnRavnAndersen Before submitting a bug report, always make sure that not using an outdated version and that the problem has not yet been reported by someone else. – howlger May 17 '19 at 06:20
  • @howlger Yes. Others took care of that. Do we agree this looks like a bug in the eclipse compiler? – Thorbjørn Ravn Andersen May 17 '19 at 15:45
  • @ThorbjørnRavnAndersen Nope, you would have to know the caller of the `resolveAnnotations` method for that. It is quite unlikely that this is a bug in the current release of Eclipse JDT. The current Eclipse release is two months old and there are zero bug reports containing the string `ASTNode.java:817`. Much more likely it is caused by a third-party plug-in. Unfortunately the stack trace is truncated. Please run `new ArrayList().get(1);` and look at the first stack trace item. Do you think this looks like a bug that should be reported to Oracle? – howlger May 17 '19 at 16:27
  • @WJS - I used multiple versions of eclipse 2019-03, 2018-09 and Neon, all are showing this issue.I am working on Mac machine and jdk version is 1.8.0_211-b12 – user837593 May 20 '19 at 14:44

4 Answers4

27

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

dansomething
  • 693
  • 8
  • 7
  • I got this error sometimes not often and 1.18.2 did not work as well. So I am using 1.16.18 without any errors! – prashanth-g Jun 10 '19 at 08:35
  • 1
    The issue should be fixed in the current lombok snapshot (https://projectlombok.org/download-edge) and in the forthcoming release 1.18.10. – Jan Rieke Aug 29 '19 at 21:33
  • I just got the error on Lombok 1.18.8, but then I updated to the most recent lombok version (1.18.10) and the exception is gone. – shiramy Sep 17 '19 at 20:00
  • Worked for me!..I think lombok does not support in @JsonProperty POJO's. Thank you so much for the answer – Kiran Kawade Aug 11 '21 at 12:54
10

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.

  • You are right. in my case also error went after commenting this annotation. I have one doubt, in other class also this annotation is there, but this error coming for only one class. any idea? – Satish Patro Apr 23 '21 at 07:11
5

Try updating lombok to the most recent version (Download 1.18.10). It worked for me.

shiramy
  • 789
  • 8
  • 13
  • 1
    For those like me who updated the maven/gradle dependency's version that won't fix your IDE problem, you have to download the lombok JAR file (for instance 1.18.10), execute the jar, and point the installation program to your IDE's main directory. – atavio Nov 29 '19 at 20:33
  • This was the solution for my case! I heard that it is related to @JsonProperty – Mohammed H Dec 17 '19 at 05:31
1

In my case the "Internal compiler error: java.lang.ClassCastException" came from a different version of lombok.jar - one was installed in the eclipse directory as javaagent and the second was in my maven project. After updating the lombok.jar in the eclipse directory anything works fine.

Hope this helps.

Conny Kreyßel
  • 687
  • 5
  • 9