Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » [SOLVED] Changing unreachable code behavior
[SOLVED] Changing unreachable code behavior [message #1859295] Sun, 28 May 2023 20:54 Go to next message
Eclipse UserFriend
Hi. It's not uncommon for me to throw a return in the middle of a method when debugging so I can test the beginning and not have it continue. In C# and PHP, they don't care. Java though makes it uncompilable. Quite irritating, as I have to do like if (1==1) return;

I saw in Preferences, Java, Compiler, Errors/Warnings you can change behavior for many things, but sadly unreachable code is not one of them. I saw "dead code" but it was set to warning so I assume that's not the same thing, as this is straight up red underlined non-compilable. I tried setting it to ignore anyway, but yea, had no effect.

Is there a way to change it to just a warning?

[Updated on: Mon, 29 May 2023 23:32] by Moderator

Re: Changing unreachable code behavior [message #1859297 is a reply to message #1859295] Mon, 29 May 2023 02:20 Go to previous messageGo to next message
Eclipse UserFriend
Some things are just required to be errors by the Java specification. I just use if (Boolean.TRUE) return instead.
Re: Changing unreachable code behavior [message #1859298 is a reply to message #1859297] Mon, 29 May 2023 03:21 Go to previous messageGo to next message
Eclipse UserFriend
I use "assert false;" which ensures I eventually go back to fix it. And often "// XXX" too so that the Markers View shows my higher priority FIXMEs.

Make sure -ea is in use in Window->Preferences->Java->JUnit, and retrofit to all existing launches.

.
Re: Changing unreachable code behavior [message #1859304 is a reply to message #1859295] Mon, 29 May 2023 15:26 Go to previous messageGo to next message
Eclipse UserFriend
"Uncompilable" with what error message?
Re: Changing unreachable code behavior [message #1859305 is a reply to message #1859298] Mon, 29 May 2023 23:32 Go to previous messageGo to next message
Eclipse UserFriend
Ugh, I guess I'm stuck with it. Thanks anyway all.

Nitin Dahyabhai wrote on Mon, 29 May 2023 19:26
"Uncompilable" with what error message?

"Unreachable code"
Re: Changing unreachable code behavior [message #1859720 is a reply to message #1859305] Fri, 23 June 2023 04:02 Go to previous message
Eclipse UserFriend
Hey Ken, good to hear your issue is resolved, albeit not the way you'd hoped. As Ed and Ed Willink suggested, using "if (Boolean.TRUE) return;" or "assert false;" are nifty workarounds. Java's strictness can be a bit frustrating when debugging, but it also helps avoid some more subtle bugs down the line. Remember, each language has its quirks.
Previous Topic:Eclipse 2021-12 to access DB2 Database
Next Topic:Weird invalid Java error
Goto Forum:
  


Current Time: Wed Jul 02 19:22:50 EDT 2025

Powered by FUDForum. Page generated in 0.03126 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top