debugger stop button behaving weirdly
-
I am using IntelliJ IDEA 2023.3.1 (Community Edition), and I'm seeing some weirdness. I made a simple test.
public class SimpleBreakTest {
public static void main(String\[\] args) { String a = null; a.toUpperCase(); }
}
I put a breakpoint on the first line: String a = null; Then, I debugged the program, and it stopped at the breakpoint. Then, I pressed the "Stop" button in the debugger. Instead of stopping execution, it looks like it continued because it printed out this message: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.toUpperCase()" because "a" is null at SimpleBreakTest.main(SimpleBreakTest.java:5) Any ideas why the stop button in the debugger doesn't seem to work right? Thanks.
-
I am using IntelliJ IDEA 2023.3.1 (Community Edition), and I'm seeing some weirdness. I made a simple test.
public class SimpleBreakTest {
public static void main(String\[\] args) { String a = null; a.toUpperCase(); }
}
I put a breakpoint on the first line: String a = null; Then, I debugged the program, and it stopped at the breakpoint. Then, I pressed the "Stop" button in the debugger. Instead of stopping execution, it looks like it continued because it printed out this message: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.toUpperCase()" because "a" is null at SimpleBreakTest.main(SimpleBreakTest.java:5) Any ideas why the stop button in the debugger doesn't seem to work right? Thanks.
... because a to upper without an assignment makes no sense anyway.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
I am using IntelliJ IDEA 2023.3.1 (Community Edition), and I'm seeing some weirdness. I made a simple test.
public class SimpleBreakTest {
public static void main(String\[\] args) { String a = null; a.toUpperCase(); }
}
I put a breakpoint on the first line: String a = null; Then, I debugged the program, and it stopped at the breakpoint. Then, I pressed the "Stop" button in the debugger. Instead of stopping execution, it looks like it continued because it printed out this message: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.toUpperCase()" because "a" is null at SimpleBreakTest.main(SimpleBreakTest.java:5) Any ideas why the stop button in the debugger doesn't seem to work right? Thanks.
-
... because a to upper without an assignment makes no sense anyway.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
I am using IntelliJ IDEA 2023.3.1 (Community Edition), and I'm seeing some weirdness. I made a simple test.
public class SimpleBreakTest {
public static void main(String\[\] args) { String a = null; a.toUpperCase(); }
}
I put a breakpoint on the first line: String a = null; Then, I debugged the program, and it stopped at the breakpoint. Then, I pressed the "Stop" button in the debugger. Instead of stopping execution, it looks like it continued because it printed out this message: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.toUpperCase()" because "a" is null at SimpleBreakTest.main(SimpleBreakTest.java:5) Any ideas why the stop button in the debugger doesn't seem to work right? Thanks.
It is of course not really worth figuring it out. And presuming you can replicate it. But if you are just curious and have time... Try adding a few more statements and see what happens. Statements before and/or after. The only thing I can think of is that code optimization is in play. Generally I would not expect that but perhaps that is exactly the cause. If it is an optimization then I would expect the following might fix it (in that Stop will work.)
String a = null;
int i = 3;
a.toUpperCase();
System.out.println("i=" + i); -
Well that is true specifically but in general it isn't relevant. The code is a valid statement. If it was a different method it might do something. And there is no way the debugger should be figuring that out.
Valid, not valid. He's created an "illogical" scenario what with null assignments, etc. Sorry, I don't blame the compiler or run time. (I frankly have no patience for this type of "nonsense"). And it's hearsay ... Did you "test" it?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
I am using IntelliJ IDEA 2023.3.1 (Community Edition), and I'm seeing some weirdness. I made a simple test.
public class SimpleBreakTest {
public static void main(String\[\] args) { String a = null; a.toUpperCase(); }
}
I put a breakpoint on the first line: String a = null; Then, I debugged the program, and it stopped at the breakpoint. Then, I pressed the "Stop" button in the debugger. Instead of stopping execution, it looks like it continued because it printed out this message: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.toUpperCase()" because "a" is null at SimpleBreakTest.main(SimpleBreakTest.java:5) Any ideas why the stop button in the debugger doesn't seem to work right? Thanks.
I am using JDK 18.0.2, and the compiler optimises out those two lines, as they obviously serve no purpose. I cannot find an option to prevent the optimisation. [edit] I had the wrong configuration settings. Tried again and it did exactly the same. I think the debugger stops, but it runs the code to the end of the current method. More tests may help to confirm this. [/edit]
-
Valid, not valid. He's created an "illogical" scenario what with null assignments, etc. Sorry, I don't blame the compiler or run time. (I frankly have no patience for this type of "nonsense"). And it's hearsay ... Did you "test" it?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
All of that is true to the extent that it isn't worth spending time on anyways (which I stated in my other post.)
Gerry Schmitz wrote:
Did you "test" it?
Not relevant. If the OP can replicate it and I can't then nothing is proven. If I can replicate it then it still doesn't change the fact that it is not worth spending time on figuring it out. Not for me at least.