Search code examples
javaeclipsedebuggingeclipse-jdt

How to debug Java SE 6 using Eclipse 2022-12?


I cannot debug Java SE 6 using Eclipse 2022-12, It throws the following exception:

java.lang.UnsupportedClassVersionError: org/eclipse/jdt/launching/internal/javaagent/Premain : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown Source)
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Unknown Source)
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main" 

However, I can run this project (Java SE 6) without any problem. I can also run and debug another Java SE 7 normally.

It's same as the problem posted here: https://www.eclipse.org/forums/index.php/mv/msg/1112218/1856754/

It's maybe happen since this change: https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/61

So. is there a way to debug Java SE 6 using eclipse 2022-12, thank you.


Solution

  • TL;DR

    • Downgrade your Eclipse up to 2022-09
    • Double check Java version after that

    Long story

    A colleague had this problem today and after some tinkering we've got it to work. His Eclipse was also stopping at a ghost breakpoint. He had never ever worked on that project and we had cleaned up everything, but even then, it would stop at a breakpoint and break with the mentioned error.

    After reading the links in this question, now I understand why this worked, but the second item was very unexpected:

    • I was on 2022-03 where it was working, so we downgraded his Eclipse to 2022-03 as well. As you pointed out, it seems they have made a change that created this bug during debug mode for Java 1.6.
    • After that, we double checked Java version everywhere and we found out that the Java 1.6 that was showing up on Eclipse was actually a Java 11 (it was written like "JavaSE-1.6 (jdk 11)"), so we forced it to use from a new Java 1.6 location. I assume Eclipse mixed up something, because I think it runs on Java 11.

    After that, debug was working again.