Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Feature Request: Warn when there is an if statement with empty body(I would like a feature where the IDE warns when there is an if statement with an empty body)
Feature Request: Warn when there is an if statement with empty body [message #1861053] Sat, 16 September 2023 00:27 Go to next message
Eclipse UserFriend
Hello all:

I just spent a full day trying to track down a bug. It turned out I accidentally put a semicolon after an if statement so the body was empty and the conditional code was always executing.

I can't imagine any use for an if statement with an empty body. It would be a very nice feature for the IDE to generate warnings for any if statements with an empty body.

Thank you,
Neil

[Updated on: Sat, 16 September 2023 13:00] by Moderator

Re: Feature Request: Warn when there is an if statement with empty body [message #1861058 is a reply to message #1861053] Sun, 17 September 2023 02:34 Go to previous messageGo to next message
Eclipse UserFriend
I have a feeling that Window -> Preferences -> Java -> Compiler -> Errors/Warnings ... Potential programming problems -> Empty statement will highlight such a problem which messages like this:
Multiple markers at this line
	- Empty control-flow statement
	- Unnecessary semicolon
Re: Feature Request: Warn when there is an if statement with empty body [message #1861059 is a reply to message #1861058] Sun, 17 September 2023 03:28 Go to previous messageGo to next message
Eclipse UserFriend
Hi all,

Never happen to me, but you never knows....

There is a check for "Empty block" but the default is ignore.

When enabled, you get this:

index.php/fa/43513/0/

IMHO, the default for "Potential programming problems" should be at least a warning.







Re: Feature Request: Warn when there is an if statement with empty body [message #1861060 is a reply to message #1861058] Sun, 17 September 2023 11:13 Go to previous messageGo to next message
Eclipse UserFriend
Quote:
Empty statement will highlight such a problem


Yes, that is exactly what I was looking for, thank you!


Quote:
default for "Potential programming problems" should be at least a warning.


I agree, that would be a nice change.
Re: Feature Request: Warn when there is an if statement with empty body [message #1861068 is a reply to message #1861053] Mon, 18 September 2023 06:32 Go to previous messageGo to next message
Eclipse UserFriend
I agree with you that it would be a nice feature for IDEs to generate warnings for if statements with empty bodies. It is a common mistake to make, and it can be difficult to track down.

There are a few potential uses for an if statement with an empty body, but they are generally not recommended. For example, you could use an if statement with an empty body to skip over a section of code if a certain condition is met. However, this is usually better done with a comment or a conditional statement that actually does something.

Another potential use for an if statement with an empty body is to create a placeholder for code that you plan to add later. However, this is also not generally recommended, as it can lead to forgetting to add the code later, or to bugs if the code is added incorrectly.
Re: Feature Request: Warn when there is an if statement with empty body [message #1861084 is a reply to message #1861068] Tue, 19 September 2023 04:59 Go to previous messageGo to next message
Eclipse UserFriend
There's an option to "info" certain warnings. Perhaps, we can look at it to change the default to info, if someone reports an issue with these reasons.
Re: Feature Request: Warn when there is an if statement with empty body [message #1861086 is a reply to message #1861084] Tue, 19 September 2023 07:31 Go to previous message
Eclipse UserFriend
Jay Arthanareeswaran wrote on Tue, 19 September 2023 08:59
There's an option to "info" certain warnings. Perhaps, we can look at it to change the default to info, if someone reports an issue with these reasons.


I agree "info" is much better than ignore.
Previous Topic:Subset Sum Problem in Java
Next Topic:Java 21 Unnamed Classes and Instance Main Methods Support in IDE
Goto Forum:
  


Current Time: Fri Apr 18 13:41:52 EDT 2025

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

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

Back to the top