How to set breakpoint in Eclipse in a third-party library?

I get a NullPointerException in a class from a third-party library. Now I would like to debug all this, and I will need to find out from which object this class is held. But it seems to me that I cannot set a breakpoint in the class from a third party.

Does anyone know a way out of my problem? Of course I use Eclipse as my IDE.

Update: open source library.

+51
java debugging eclipse breakpoints
Dec 16 '08 at 9:42
source share
6 answers

The most reliable way to do this (and end up with something really useful) is to download the source code (you say it is open source) and set up another "Java Project" pointing to that source.

To do this, download the source code and unzip it somewhere on your system. Click File → New → Java Project. In the next dialog box, specify the name of the project and select "Create a project from an existing source." Go to the root location of the open source library.

Assuming all the additional libraries that a project needs, etc., are included in the loaded project, Eclipse will select everything and set the build path for you.

You need to remove the open source jar from the project creation path and add this new project to the build path of your project.

Now you can simply consider this as your code and debug as you wish.

This applies to at least a few issues with other approaches:

  • You could “attach the source” to the jar file, but if the jar file was compiled without debugging information, it still wouldn't work. If the jar file was compiled with debug information ( lines,source,vars ... see http://java.sun.com/j2se/1.3/docs/tooldocs/win32/javac.html and the -g option).

  • You can add a “control point of exception” to see when a NullPointerException is raised, but this is a general exception, and it can be raised and handled many (hundreds?) Times before the one you are looking for. Plus, without the original source, you won’t be able to really see anything about the code that throws a NullPointerException - the likelihood that you can understand what is wrong is pretty low.

+31
Dec 16 '08 at 20:39
source share

You can easily set method breakpoints in third-party libraries without a source. Just open the class (you get the "i-have-no-source" view). Open the diagram, right-click the desired method and click Toggle Method Breakpoint to create a breakpoint for the method.

+56
Dec 16 '08 at 9:45
source share

You can also set breakpoints for specific exceptions. From Debug's point of view, there is a “Add Java Exception Exception Point” button, and there you can add a “NullPointerException”. After that, the debugger pauses execution as soon as such an exception occurs.

+6
Dec 16 '08 at 10:29
source share

Generally, you should be able to set a breakpoint. Especially if the third-party library is open source. But if your third-party library is owned by a commercial vendor, they can compile the source with the debug flag disabled. This will not allow you to debug it. Perhaps your provider did this as part of the obfuscation process to make reverse library design impossible, or simply because the final compiled classes will be smaller.

+1
Dec 16 '08 at 10:25
source share

Just attach the source (or use something that automatically attaches the original jar), and then set the breakpoint in the usual way by double-clicking to the left of the line of interest.

+1
Sep 28 '12 at 12:26
source share

To do this work with the maven materialized web application, I had to do three things.

1) Create a new eclipse project with the source code of a third-party jar.

2) Remove jar reference from pom.xml dependencies.

3) Add a new eclipse project to the deployment assembly in the project properties.

4) Add a new eclipse project to the project Properties → Java Build Path → Projects of an existing project that references a third-party project.

If the third project was added to your maven repository correctly, with sources, maven will automatically download the appropriate source code and add breakpoints without having to perform any of the steps above; however, I found out that you cannot always count on it.

+1
Oct. 12 '15 at 19:43
source share



All Articles