Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » [SOLVED] Changing unreachable code behavior
[SOLVED] Changing unreachable code behavior [message #1859295] Mon, 29 May 2023 00:54 Go to next message
Ken Nischan is currently offline Ken NischanFriend
Messages: 7
Registered: December 2019
Junior Member
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: Tue, 30 May 2023 03:32]

Report message to a moderator

Re: Changing unreachable code behavior [message #1859297 is a reply to message #1859295] Mon, 29 May 2023 06:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33264
Registered: July 2009
Senior Member
Some things are just required to be errors by the Java specification. I just use if (Boolean.TRUE) return instead.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Changing unreachable code behavior [message #1859298 is a reply to message #1859297] Mon, 29 May 2023 07:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7681
Registered: July 2009
Senior Member
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 19:26 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4507
Registered: July 2009
Senior Member

"Uncompilable" with what error message?

_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Changing unreachable code behavior [message #1859305 is a reply to message #1859298] Tue, 30 May 2023 03:32 Go to previous messageGo to next message
Ken Nischan is currently offline Ken NischanFriend
Messages: 7
Registered: December 2019
Junior Member
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 08:02 Go to previous message
Kabiru Usman is currently offline Kabiru UsmanFriend
Messages: 42
Registered: April 2023
Member
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: Sat Jan 25 10:26:33 GMT 2025

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

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

Back to the top