Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm getting a NullPointerException in a Class from a 3rd party library. Now I'd like to debug the whole thing and I would need to know from which object the class is held. But it seems to me that I cannot set a breakpoint in a Class from a 3rd party.

Does anyone know a way out of my trouble? Of course I'm using Eclipse as my IDE.

Update: the library is open-source.

like image 245
boutta Avatar asked Dec 16 '08 09:12

boutta


People also ask

How do I set breakpoint conditions in Eclipse?

To create a conditional breakpoint, first set a breakpoint on a line (Ctrl+Shift+B), right-click on the breakpoint and select Breakpoint Properties. Then configure a condition that returns a boolean. Eclipse only stops if the conditions returns true.

How do I import breakpoints in Eclipse?

If you can't find the Breakpoints tab, open it on: Window > Show View > Breakpoints . Then, as said before: Ctrl+A to select all breakpoints > right click > Export Breakpoints... .

How do I add a breakpoint to all methods in Eclipse?

Select all the methods using ctrl . Right click and select Toggle Method Breakpoint .

Can not set breakpoint in Eclipse?

in python, I had to go to: windows->perspective->Open Perspective->Debug then select the Breakpoints tab and make sure the zero with the slash (skip all breakpoints) is not selected (you can also use Ctrl-Alt-B to toggle it). Show activity on this post. Show activity on this post.


2 Answers

You can easily set method breakpoints in 3rd party libraries without having the source. Just open the class (you'll get the "i-have-no-source" view). Open the outline, right-click on the method you want and click on Toggle Method Breakpoint to create the method breakpoint.

like image 109
Joachim Sauer Avatar answered Oct 13 '22 22:10

Joachim Sauer


The most sure-fire way to do this (and end up with something that's actually useful) is to download the source (you say that it is open-source), and set up another "Java Project" pointing at that source.

To do that, get the source downloaded and unzipped somewhere on your system. Click "File"->"New"->"Java Project". In the next dialog, give it a project name and select "Create Project from Existing Source". Browse to the root location of the open source library.

Supposing that all the additional libraries that are required by the project and such are included in the project you downloaded, Eclipse will figure everything out and set the build path up for you.

You'll need to remove the open source jar from your project's build path, and add this new project to the build path of your project.

Now, you can just treat this as your code, and debug at will.

This gets around at least a couple of problems with other approaches:

  1. You could "attach source" to the jar file, but if the jar file was compiled without debug information, this still won'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).

  2. You could add an "exception breakpoint" to see when the NullPointerException is raised, but that's a common exception, and may well get raised and dealt with many (hundreds of?) times prior to the one you're looking for. Plus, without the original source, you won't be able to really see much of anything about the code that is throwing the NullPointerException - the likelihood you'll be able to figure out what's wrong is pretty low.

like image 35
Jared Avatar answered Oct 13 '22 21:10

Jared