views:

917

answers:

2

I have a really strange issue. I am working on a Java SWING application in Eclipse. I set a breakpoint somewhere in my code, then run the debug. I execute the piece of code containing the breakpoint but it is always skipped. As soon as I run some code that throws an uncaught exception, the breakpoints start being hit again, without changing anything else. The code that throws the exception and the one containing the breakpoint are not related.

I tried to set the breakpoints in several places but they never get hit until the exception is thrown. I have this problem only for this one specific application. My debugger works fine for other SWING apps.

Can you think of any reason causing this?

A: 

Have you started the GUI in a seperate thread? I don't recognize your particular problem, but a lot of strange problems disappeared once I started to use this code from the java tutorials :

SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        createAndShowGUI();
    }
});
Peter
Ahhhh...the good ol' invokelater. I remember the time when I superstitiously used it any time I ever had any Swing problems. I even had a nested call to it once.
Epaga
+6  A: 

What exact version of eclipse and Java are you running?

Are you aware of this question? (bug 279137: Breakpoints fail to hit under JDK 1.6.0_14 )


As gojomo remarks in the comments, that bug (279137) now (July 21 2009) mentions:

The bug is now visible in the sun bug database: bug 6862295.

We have listed a workaround for this problem, which can be used while we investigate a fix for the bug.

Work Around

Using the option -XX:+UseParallelGC makes the failure not reproducible with either the Client VM or the Server VM.

(Option yo add to the eclipse.ini)

I would recommend that you use the 'watch this bug' feature, so you can be notified when there are updates to the bug. Here is the link to watch this specific bug


FIXED

As the release note of the jdk6_u16 (late August 2009) mentions, that bug has been fixed

Bug fixed in this release:

6862295 JDWP threadid changes during debugging session (leading to ignored breakpoints)

VonC
I experienced this a lot. Thank you for the bug report link.
kd304
I think this may be the reason. I tried to download the 1.6.0_13 but I cannot find it anywhere. Does anyone have a link?
AndreaC
@Andrea: For downloading java6u13 (previous release before the current 14 one), you can go to: http://java.sun.com/products/archive/j2se/6u13/index.html
VonC
Thanks a lot! This seems to have solved the problem.
AndreaC
@AndreAC glad to hear it. I hope java6u15 will fix this issue. Do not forget you can launch your eclipse with java6u14 (for latest Hotspot optimizations and a speedier eclipse), but declared within eclipse as default JRE a jdk6u13 (for compilation and running your programs)
VonC
The bug now mentions another workaround for 6u14: use the JVM option: -XX:+UseParallelGC
gojomo
The fix for bug 6862295 has been released in Java 6 update 16
Stephen Denne
@spdenne: thank you for this reminder (I knew about this release, I just had forgotten about this answer!). This post has now been updated.
VonC