Search code examples
javadebuggingjvmjvm-hotspot

Third party library (JAR) does not work in debug mode (Java)


In my java project I use a third party library (jar) and call a function of that library at start.

public static void main(String args[]) {
   long handle = Library.method(params);
   if (0 == handle) {
      // error
   }
}

Use eclipse for the development. The question is, when I run the project (call the main) in RUN mode, I get the handle. But when I call with DEBUG mode (without any breakpoints attached), I do not get the handle. (The run/debug settings are the same, no additional VM or program parameters)

Question:

  • How can the library detect that it is called in the debug mode and prevent returning the handle?
  • How can I debug this project (I need some debug)

Solution

  • How can the library detect that it is called in the debug mode and prevent returning the handle?

    There are ways, for instance:

    How to find out if "debug mode" is enabled

    But it is surely not possible to assemble the complete list of possibilities.

    How can I debug this project (I need some debug)

    You'll either need to find a debuggable version (maybe available from the developer of the library for additional fees?) or overcome the protection.

    One-guy-I-know-who-isn't-me would for instance first try to disassemble the library to find out how is it actually protected. If disassembly succeeds then it might be even possible to remove the protection.