|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
catching infinite loops in a for / while loopHi
All,
Findbugs has the following set of infinite loop
detectors currently available.
IL: A collection is added to itself
(IL_CONTAINER_ADDED_TO_ITSELF) - A collection is added to itself. As a
result, computing the hashCode of this set will throw a StackOverflowException.
IL: An apparent infinite loop
(IL_INFINITE_LOOP) - This loop doesn't seem to have a way to terminate
(other than by perhaps throwing an exception).
IL: An apparent infinite recursive loop
(IL_INFINITE_RECURSIVE_LOOP) - This method unconditionally invokes
itself. This would seem to indicate an infinite recursive loop that will result
in a stack overflow.
Is
there any detector available or are there any plans to write a detector to catch
infinite loops in a for / while loop?
For
example:
StringTokenizer tokenizer = new StringTokenizer("a,b,c",",");
String happyPath= null;
while(tokenizer.hasMoreTokens()){ if(null != happyPath){ System.out.print("Token: " + tokenizer.nextToken()); } } In the above code sample, if happyPath is null, the control can never come out of the loop. thanks, Abhijit
_______________________________________________ Findbugs-discuss mailing list Findbugs-discuss@... https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss |
|
|
Re: catching infinite loops in a for / while loopMaybe.
The problem is that there are lots of various different ways that a loop can be non-terminating, and each one would likely require special logic. In your example code, the problem is that the code doesn't call nextToken(). Similar patterns exist for Iterator and Enumerator. But you also have to worry about whether the StringTokenizer / Iterator / Enumerator escapes the local stack frame. If so, the "advance to next element" method might be called by some other method. Perhaps we could prototype something and evaluate it, but I'm unsure that we'd get much bang for the buck. The existing infinite loop bug patterns aren't the most important or effective bug patterns, and I'd suspect that these would be even less profitable. Bill
_______________________________________________ Findbugs-discuss mailing list Findbugs-discuss@... https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss |
|
|
Re: catching infinite loops in a for / while loopHi Bill,
These patterns may not make much sense for a desktop
application or for a low traffic web application scenario. But when you look at
a high traffic web application with millions of requests, you can see OOMs with
in few moments of starting the JVM. So that's a P1 scenario.
thanks,
Abhijit From: Bill Pugh [mailto:pugh@...] Sent: Thursday, August 13, 2009 12:55 PM To: Pani, Abhijit Cc: findbugs-discuss@... Subject: Re: [FB-Discuss] catching infinite loops in a for / while loop The problem is that there are lots of various different ways that a loop
can be non-terminating, and each one would likely require special logic.
In your example code, the problem is that the code doesn't call
nextToken().
Similar patterns exist for Iterator and Enumerator.
But you also have to worry about whether the StringTokenizer / Iterator
/ Enumerator escapes the local stack frame. If so, the "advance to next
element" method might be called by some other method.
Perhaps we could prototype something and evaluate it, but I'm unsure that
we'd get much bang for the buck. The existing infinite loop bug patterns aren't
the most important or effective bug patterns, and I'd suspect that these would
be even less profitable.
Bill
_______________________________________________ Findbugs-discuss mailing list Findbugs-discuss@... https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss |
|
|
Re: catching infinite loops in a for / while loopThe question isn't whether or not they could occur and would be serious if they occurred in production.
The question is for each bug pattern you'd have to create, how often would the mistake get made, and if the mistake got made, how likely would it escape testing yet occur in production. Do you have any experience with this bug occurring in production? Bill On Aug 13, 2009, at 5:49 PM, Pani, Abhijit wrote:
_______________________________________________ Findbugs-discuss mailing list Findbugs-discuss@... https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss |
|
|
Re: catching infinite loops in a for / while loopHi Bill,
The issue was detected in production. We can't simulate
the same issue in QA environment because it's hard to create same kind of
traffic as production.
thanks,
Abhijit
From: Bill Pugh
[mailto:pugh@...]
The question isn't whether or not they could occur and would be
serious if they occurred in production.
Sent: Thursday, August 13, 2009 7:35 PM To: Pani, Abhijit Cc: findbugs-discuss@... Subject: Re: [FB-Discuss] catching infinite loops in a for / while loop The question is for each bug pattern you'd have to create, how often would
the mistake get made, and if the mistake got made, how likely would it escape
testing yet occur in production.
Do you have any experience with this bug occurring in production?
Bill
On Aug 13, 2009, at 5:49 PM, Pani, Abhijit wrote:
_______________________________________________ Findbugs-discuss mailing list Findbugs-discuss@... https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss |
|
|
Re: catching infinite loops in a for / while loopHi, I don't see how the code sample in the first mail depends on high volume to produce an infinite loop. Could you please provide some more detail of why this happens? Is there a race condition that causes the variable "happyPath" to be null? Tomás From: "Pani, Abhijit" <apani@...> To: Bill Pugh <pugh@...> Cc: findbugs-discuss@... Sent: Monday, August 17, 2009 1:37:49 PM Subject: Re: [FB-Discuss] catching infinite loops in a for / while loop Hi Bill,
The issue was detected in production. We can't simulate
the same issue in QA environment because it's hard to create same kind of
traffic as production.
thanks,
Abhijit
From: Bill Pugh
[mailto:pugh@...]
The question isn't whether or not they could occur and would be
serious if they occurred in production.
Sent: Thursday, August 13, 2009 7:35 PM To: Pani, Abhijit Cc: findbugs-discuss@... Subject: Re: [FB-Discuss] catching infinite loops in a for / while loop The question is for each bug pattern you'd have to create, how often would
the mistake get made, and if the mistake got made, how likely would it escape
testing yet occur in production.
Do you have any experience with this bug occurring in production?
Bill
On Aug 13, 2009, at 5:49 PM, Pani, Abhijit wrote:
_______________________________________________ Findbugs-discuss mailing list Findbugs-discuss@... https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss |
|
|
Re: catching infinite loops in a for / while loopHi Tomas,
happyPath is null before entering the loop. The iterator
will never advance to the next element as tokenizer.nextToken() never gets
executed. So the code sample will always create an infinite
loop.
thanks,
Abhijit From: Tomas Pollak [mailto:tomas_pollak@...] Sent: Monday, August 17, 2009 6:01 PM To: Pani, Abhijit; Bill Pugh Cc: findbugs-discuss@... Subject: Re: [FB-Discuss] catching infinite loops in a for / while loop Hi,
I don't see how the code sample in the first mail depends on high volume to produce an infinite loop. Could you please provide some more detail of why this happens? Is there a race condition that causes the variable "happyPath" to be null? Tomás From: "Pani, Abhijit" <apani@...> To: Bill Pugh <pugh@...> Cc: findbugs-discuss@... Sent: Monday, August 17, 2009 1:37:49 PM Subject: Re: [FB-Discuss] catching infinite loops in a for / while loop Hi Bill,
The issue was detected in production. We can't simulate
the same issue in QA environment because it's hard to create same kind of
traffic as production.
thanks,
Abhijit
From: Bill Pugh
[mailto:pugh@...]
The question isn't whether or not they could occur and would be
serious if they occurred in production.
Sent: Thursday, August 13, 2009 7:35 PM To: Pani, Abhijit Cc: findbugs-discuss@... Subject: Re: [FB-Discuss] catching infinite loops in a for / while loop The question is for each bug pattern you'd have to create, how often would
the mistake get made, and if the mistake got made, how likely would it escape
testing yet occur in production.
Do you have any experience with this bug occurring in production?
Bill
On Aug 13, 2009, at 5:49 PM, Pani, Abhijit wrote:
_______________________________________________ Findbugs-discuss mailing list Findbugs-discuss@... https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss |
| Free embeddable forum powered by Nabble | Forum Help |