Missing inspection for infinite loop

I was surprised to discover that IDEA has nothing to say about this code:

int count = 0;
while (count < 10) {
System.out.println("count = " + count);
}

I guess it wouldn't be too hard to figure out that the loop condition is
always false.
Making 'count' final triggers the inspection 'Condition is always true'.

/Mikael


8 comments

Try the "Loop variable not updated inside loop" inspection. That should do what you want.

Bas

0

That inspection was disabled. Strange. Nice to see that it exists. It flags
the variable.
It doesn't figure out that the loop never terminates. Making the variable
final does.

/Mikael

"Bas Leijdekkers" <no_reply@jetbrains.com> wrote in message
news:3250645.1175771791277.JavaMail.itn@is.intellij.net...

Try the "Loop variable not updated inside loop" inspection. That should do
what you want.

>

Bas



0

I do not understand what you mean. The "loop variable not updated inside loop" inspection highlights the variable when it is enabled, does it not? Do you think it should be enabled by default? If it is not working for you, what is the build number of the IDEA you are using?

Bas

0

He is wondering why 'Condition is always true' doesn't trigger when the
variable is not final. (I'm wondering too, as there's no possibility to
have them changed by whatever side effect.)

Bas Leijdekkers wrote:

I do not understand what you mean. The "loop variable not updated inside loop" inspection highlights the variable when it is enabled, does it not? Do you think it should be enabled by default? If it is not working for you, what is the build number of the IDEA you are using?

Bas

0

Ah, that is part of the "Constant conditions & exceptions" inspection, now I understand. Please submit a bug report to JIRA.

Bas

0

On 2007-04-06 15:19:22 +0400, Bas Leijdekkers <no_reply@jetbrains.com> said:

Ah, that is part of the "Constant conditions & exceptions" inspection,
now I understand. Please submit a bug report to JIRA.

Bas


Constant conditions only handles != and == relations for now and cannot
handle > and <

0

But then why does it trigger when making the variable final?

Constant conditions only handles != and == relations
for now and cannot
handle > and <

>

0

On 2007-04-07 02:58:57 +0400, Martin Fuhrer <mf@fuhrer.com> said:

But then why does it trigger when making the variable final?

>> Constant conditions only handles != and == relations
>> for now and cannot
>> handle > and <

You've got me Martin :) I'll investigate what's happening in more details.

0

Please sign in to leave a comment.