I am debugging RCP( multi-threaded GUI application) using Eclipse Helios.
When I am executing the same method, I get a null pointer exception in run mode, but in
debug mode, I don't get any exception. I think it works fine in Debug mode.
Null pointer exception doesn't come in debug mode , but in run mode only..
Please help me out. Could it be a multi-threading issue.
Different behavior in run and debug mode is not unusual. Once I spent a day to find that a toString() had side effects. The debugger calls this method when displaying variables. Another reason for differences is concurrency. The execution order in the debugger may be different from run mode.
You can add a breakpoint to the line that NPE happened in run mode. And you need set the property of breakpoint to pause the entire vm.
Then debugging your program, the entire vm will be suspended when a thread tries to execute that line. You can let other threads which don't try to execute that line to resume, the second thread will be suspended on that line as well. You can analysis the flaw of your code.
Please check whether you have used for each to traverse a collection. The traversal order of the collection may be inconsistent between run and debug, which may lead to different results.
Related
I'm currently trying to write a new program, but for some reason my eclipse is suspending every 30 seconds or so. I think that it has something to do with the new code I've been writing.
I'm using eclipse 21-03, my Wildfly Server is Version 21.0.2 and I'm using openJDK-11.
I already tried giving eclipse more RAM, that didn't help.
You can see a picture of my Taskmanager attached. Eclipse is still using so much RAM although I stopped the server as well as the programm. What do I have to do to suspend the workspace task but not stop eclipse from running?
1.5 GB is quite normal for Eclipse. Sadly. RAM hog.
There are two possiblilities why Eclipse is suspending code:
You have set breakpoints, that are manual instructions that tell Eclipse to stop in Debugging Mode. They are little blue dots on the line numbers in the code window.
Some Exceptions fall all the way through the Stack Trace unhandled. If this happens in Debug Mode, Eclipse will halt where the Exception is thrown and tell you the reason.
Solutions:
Improve your code so that the Exceptions do not fall through. Use try-catch
Remove breakpoints you set
Do not run your app in Debug mode, but in normal run mode. This way the debugger is not attached an will not interrupt "normal" flow.
Example of an exception break in debug mode:
The popup shows that x is null, so accessing x.length() will throw a NullPointerException (NPE) that is not caught but crashes through to the Thread
In the bottom right, the Debug View shows where and why execution is halted.
I found this link on SO:
Code not working when running normally, but working in debug (eclipse)
and on seeing the answers, added a Thread.sleep(0) inside my while loop and it works.
The question is "why?". Also, is this problem specific to Eclipse?
It definitely is not specific to Eclipse. It's a threading issue and can happen in any program using threads that rely on each other. Debug makes the timing issue go away because you are essentially performing a sleep by slowing everything down to walk the code.
If you run debug multiple times with no stops you might find that your failure shows up in a few of the runs.
Making a thread sleep gives the other threads time to "catch up" and complete whatever task the sleeping thread is waiting on.
I have a problem while debugging in IntelliJ IDEA, it hangs in debug mode on break point in listeners in javafx application. I tried to increase heap space, but it's not help. Maybe someone had such problem too, please, suggest me what to do.
Set this as a VM parameter:
-Dsun.awt.disablegrab=true
It will mess up drag-and-drop, and leave an artifact on your screen while the debugger is paused - but it will let you debug. It happens whenever you block the JavaFX thread.
This can happen for a simple reason: The application has a lock on the desktop, for example a modal dialog or a popup or an open menu. Then it stops in a breakpoint. This notifies the IDE. Now the IDE tries to do something on your desktop but can't since the application still has a lock on the whole desktop -> deadlock.
You can use a tool like Chronon which records the whole program and lets you move back and forth on the timeline.
The last option is logging or poor man's debugger (System.out) instead.
[EDIT]
it's hard to check with System.out which of 20 parameters not equal.
It's actually pretty easy:
System.out.println("check");
if(!a1.equals(b2)) System.out.println(a1+"!="+b1);
Then duplicate the last line. That way, you will only get output when something is actually interesting (and not for the 19 equal parameters). Add some patterns to the output if you can't distinguish aX from aY (i.e. both are true):
if(!a1.equals(b2)) System.out.println("a1:"+a1+"!="+b1);
Is there a tool I can use to see what parts of the code are in which thread (colour code it or something)? I'm mostly concerned about EDT, but writing that isOnEventDispatchThread()-ish command every other line and then keeping track of it's output while the program is running is tedious and time consuming.
The major problem I'd see with this is code that can be called from any thread, such as constructors. You can however use Eclipse's debugger at runtime. Simply run the program in the debugger until a breakpoint or with manual pause then look at the "debug" view that is generally in the upper left. You'll see threads and may select one to jump to its location.
While debugging, my Eclipse pause on same line every time. I read this Eclipse pausing without a breakpoint, but there are no exceptions in my console. I also read this Why does my Eclipse project have phantom debugger breakpoints?, but it doesn't help too.
The code that pauses debugger without breakpoint is this:
Query query = sessionFactory.getCurrentSession().createQuery(hql);
I think there's no problem with createQuery(). Whenever getCurrentSession() called, my Eclipse pauses. Why is this happening?
Look into concurrency. Maybe ur running into situations like deadlock. It happens when two objects are not locked in the same order, causing two different threads to be waiting for each other to release other object.
At this point it appears that the entire program has paused. Maybe its whats happening, but cant say for sure until I can see the code.
Sometimes I face this kind of problem and everytime I end up finding out that my java code is not synchronized with my .class, this happens when I'm in remote debugging. Try to close your eclipse, clean your project and then try again. If you're debugging remotely, update your source codes.
Cheers!
Simple. Application always multithreading.. Obvously that application stop in another thread. When you analyze on which tread Eclipse stop and click on this thread - you found that Eclipse starts to react on command.