101

I am trying to trouble shoot a JUnit. In the source code, I have set break point in two places: 1) in a line where a static member is initialized 2) the first line of one of the test cases.

The debugger stops in the static field initializing line. But it doesn't stop in the test case. No matter where I set the break point in the test case, the debugger doesn't stop there. I know for sure that the test case is executed as I can see the log messages that I have added appear in the log.

Any help would be greatly appreciated.

I am using Eclipse Galileo and JUnit4 launcher.

Vineet Reynolds
  • 76,006
  • 17
  • 150
  • 174
Roy
  • 1,015
  • 2
  • 7
  • 5

23 Answers23

103

Fix could be as simple as clicking run/skip all breakpoints. Worked for me.

user1164035
  • 1,101
  • 2
  • 7
  • 5
53

Make sure, under Run > Debug Configurations, that 'Stop in main' is selected, if applicable to your situation.

Answerer
  • 539
  • 4
  • 2
  • 1
    Please be sure to read previous responses before posting. The problem was their jvm version .. and was solved three years ago. Best not to revive old threads unless your response contributes something significant, that was not already covered in previous answers. – Leigh Jun 15 '12 at 02:53
  • 7
    Thanks. @Answerer your answer solved my problem. It's strange that "Stop in main" was unset. – Yu Shen Dec 08 '12 at 06:09
  • 26
    It appears that his answer did contribute something significant that was not already covered in previous answers :) – scubbo Mar 20 '13 at 11:53
  • Note, this is an option for Java applications but not Android applications. – Noumenon Jul 13 '13 at 21:41
39

This could be related to one of the bugs in JDK 6 Update 14, as indicated in the release notes for JDK 6 update 15.

If this indeed turns out to be the issue, you should move to a higher version of the JDK (that's no guarantee though, since fixes have been released against 6u16, 6u18 and 7b1). The best bet is to use -XX:+UseParallelGC flag. Increasing the size of the minimum and maximum heap size, to delay the first GC, bring temporary relief.

By the way, use this bug report in Eclipse to track how others have been faring.

Vineet Reynolds
  • 76,006
  • 17
  • 150
  • 174
  • 1
    I upgraded to JDK 1.6 update 16. Now it stops at all the break points that I have set. Thanks a lot for your help. – Roy Sep 03 '09 at 02:43
  • You're welcome. u16 seems to be the release where this was fixed to a good enough extent, despite u15's release notes. – Vineet Reynolds Sep 03 '09 at 02:44
  • Thanks @Vineet - I was pulling my hair out over this one :-) – Jim Garrison Dec 01 '09 at 17:13
  • @VineetReynolds: I have seen your valuable answers relate to Jboss and Java ee 6. can you help me trouble shoot this problem? http://stackoverflow.com/questions/28954323/error-while-deploying-simple-web-app-in-jboss-as-6-and-jboss-as-7 – brain storm Mar 10 '15 at 18:55
23

You might have accidentally skipped all break points in Eclipse toolbar. To fix this go to Eclipse -> Run -> Skip All Breakpoints.

Jigna.Shah
  • 231
  • 2
  • 2
  • 2
    Arggh, there is a shortcut for this too, I most probably did not accidentially check a menu item, but I am rather likely to have hit Ctrl+Alt+B. Thanks anyways. – Patru Feb 05 '20 at 15:56
21

Usually when this happens to me (rare but it does) means that the code being executed is different than the code in the editor. It will happen from time to time for Eclipse that the built classes and the code in editor are out of sync. When that happens I get all sort of weird debugger behavior (debugging empty lines, skipping lines of code etc).

Restarting Eclipse, clean all projects and rebuild everything usually clears things up. I had also the Maven plugins (older versions... had not had it for a while now) that had a tendency to do that too.

Otherwise it might be a bug, maybe the one Vineet stated,

Hope this helps

starball
  • 20,030
  • 7
  • 43
  • 238
Newtopian
  • 7,543
  • 4
  • 48
  • 71
  • Yea, what you've stated happens more in IDEs that do not automatically recompile code. Oracle JDeveloper (from personal experience) and to a lesser extent (Netbeans) have been found wanting. – Vineet Reynolds Sep 03 '09 at 05:03
  • 1
    Good advice. Not said enough. Sometimes we over-think the problem and it's just the system out of synch. Such as it is with rebooting a computer for trouble shooting simple issues. – Xonatron Jun 25 '12 at 19:18
  • Thanks, that was the problem in my case. It sounds stupid, but a simple clean and F5 after a build did the job. – jfajunior May 27 '19 at 14:35
4

In my case the problem was that I hadn't Debug view open in Debug perspective, so:

1 - Be sure you have debug perspective opened:

eclipse debugger not working 1

2 - Be sure you have debug view opened:

eclipse debugger not working 2

Dani
  • 1,825
  • 2
  • 15
  • 29
3

Project -> Clean seemed to work for me on on JRE 8

JH95
  • 489
  • 1
  • 7
  • 24
2

In order to debugger work with remote, the java .class files must be complied along with debugging information. If "-g:none" option was passed to compiler then the class file will not have necessary information and hence debugger will not be able to match breakpoints on source code with that class in remote. Meanwhile, if jars/class files were obfuscated, then they also will not have any debug info. According to your responses, most probably this is not your case, but this info could be useful for others who face the same issue.

sergeyan
  • 1,173
  • 1
  • 14
  • 28
2

Remove all breakpoints and re-add them.

Raffi Khatchadourian
  • 3,042
  • 3
  • 31
  • 37
1

For JDK7, run->Debug Configurations, check "Keep JUnit running after a test run when debugging".

Frank Fu
  • 778
  • 4
  • 8
  • 12
1

Happened to me once, when I had unchecked "Run > Build automatically" and forgot to re-check it.

Mathiouss
  • 101
  • 7
1

Make sure you declare the package at the top. In my groovy code this stops at breakpoints:

package Pkg1

import java.awt.event.ItemEvent;

isMule = false

class LineItem {
    // Structure defining individual DB rows
    public String ACCOUNT_CODE
    public String ACCOUNT_DESC
...

This does not stop at breakpoints:

import java.awt.event.ItemEvent;

isMule = false

class LineItem {
    // Structure defining individual DB rows
    public String ACCOUNT_CODE
    public String ACCOUNT_DESC
...
Don Harrington
  • 87
  • 1
  • 11
0

To remove the breakpoints:

  1. Debug your class as a junit test
  2. When your debugger stops, click the "breakpoints" tab next to "variables" and "expressions"
  3. At the top right of the breakpoint tab, click the button with two 'X'
  4. Stop the test, replace your breakpoint and run the debugger again
Jamal
  • 763
  • 7
  • 22
  • 32
Cyrois
  • 439
  • 4
  • 9
0

One additional comment regarding Vineet Reynolds answer.

I found out that I had to set -XX:+UseParallelGC in eclipse.ini

I setup the virtual machine (vm) arguments as follows

-vmargs
-Dosgi.requiredJavaVersion=1.7
-Xms512m
-Xmx1024m
-XX:+UseParallelGC
-XX:PermSize=256M
-XX:MaxPermSize=512M

that solved the issue.

rsp
  • 23,135
  • 6
  • 55
  • 69
0

If nothing works-

  1. Remove that Remote/Local Debug Configuration, and Create a new One.
  2. Add the Source in Debug Configurations.
Mohammad Faisal
  • 5,783
  • 15
  • 70
  • 117
kanaparthikiran
  • 523
  • 12
  • 15
0

Also verify if breakpoints on other lines DO work, it may be a bug in the debugger. I have had a problem with the Eclipse debugger where putting a breakpoint on a boolean assignment whose code was on the next line didn't work I reported this here, but putting it on the previous or next line did.

Henno Vermeulen
  • 1,495
  • 2
  • 15
  • 25
0

Another possible problem is that the debugger port may be blocked by the firewall. For example, I was using mule anypoint studio (v 5.4.3). The default debugger port is 6666. When a flow is executed, it would not stop at breakpoint. when I changed the port to another (e.g. 8099), it worked fine.

RuntimeException
  • 1,593
  • 2
  • 22
  • 31
0

Go to Right click->Debug Configuration and check if too many debug instances are created. My issue was resolved when i deleted multiple debug instances from configuration and freshly started debugging.

priyanka_rao
  • 465
  • 1
  • 4
  • 20
0

If you are on Eclipse,

Right click on your project folder under "Package Explorer".

Goto Source -> Clean up and choose your project.

This will cleanup any mess and your break-point should work now.

Sureshbabu E
  • 91
  • 2
  • 4
0

Creating a new workspace worked for me.

Ahmed Tawila
  • 988
  • 2
  • 13
  • 20
0

In my case I had multiple projects in same workspace. The java file I was trying to debug was present in more than one projects with same package.

I didn't need the other project, so simply closed unrelated projects (or remove the file from unrelated project).

Shanu Gupta
  • 3,699
  • 2
  • 19
  • 29
0

It happened to me when I had several project, I realized that I created a spring boot configuration of a project B from a project A (I clicked on Duplicate and change the parameter to have a config for the project B) and in that case I haven't the debug mode so I removed this config and I created directly a new one by clicking New in Spring Boot App

enter image description here

Tanorix
  • 230
  • 2
  • 16
-3

This is what works for me:

I had to put my local server address in the PHP Server configuration like this:

enter image description here

Note: that address, is the one I configure in my Apache .conf file.

Note: the only breakpoint that was working was the 'Break at first line', after that, the breakpoints didn't work.

Note: check your xdebug properties in your php.ini file, and remove any you think is not required.