Bug Pattern

View: New views
8 Messages — Rating Filter:   Alert me  

Bug Pattern

by Balaji Varanasi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
 I was refactoring some of my code and I ended up with
a bug that FindBugs wasnot able to detect.

 Here is a simple version of the code:
public void main(String args[])
{
        int value = 1;
               
        // Do some stuff
               
        if(value == 1)
        {
                for(int i = 0; i < 10; i++)
                {
                        if(value == 2)
                        {
                                // Do something
                        }
                        else if(value == 3)
                        {
                                // Do something
                        }
                }
        }
}

 This is a simple oversight that might be worth if
find bugs can catch.

Thanks,
Balaji
_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

Ignored return values

by Frank Jensen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

FindBugs detects ignored return values from known methods:

"hei".substring(1);//Reports: H C RV ... ignores return value


However, it does not seem to detect ignored return values from my own
methods:

myObject.getIt();  //Reports nothing

Would it be a good idea to make a more general rule about ignored return
values? Some times the returned value is of no interest, but perhaps it
is possible to detect when they probably are. For instance if

1. The called method have no (detectable) side effects
2. The called method is a getter


Best Regards,

Frank Jensen
Oslo, Norway
_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

Re: Ignored return values

by Bill Pugh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If you apply the annotation  
edu.umd.cs.findbugs.annotations.CheckReturnValue, or
javax.annotation.CheckReturnValue (from the JSR-305 reference  
implementation),
FindBugs will report this.

We aren't going to try to guess which methods should have their return  
value checked,
at least not and generate the standard correctness warning. We might  
possibly generate a dodgy code warning.

        Bill



On May 28, 2008, at 6:15 AM, Frank Jensen wrote:

> Hello,
>
> FindBugs detects ignored return values from known methods:
>
> "hei".substring(1);//Reports: H C RV ... ignores return value
>
>
> However, it does not seem to detect ignored return values from my own
> methods:
>
> myObject.getIt();  //Reports nothing
>
> Would it be a good idea to make a more general rule about ignored  
> return
> values? Some times the returned value is of no interest, but perhaps  
> it
> is possible to detect when they probably are. For instance if
>
> 1. The called method have no (detectable) side effects
> 2. The called method is a getter
>
>
> Best Regards,
>
> Frank Jensen
> Oslo, Norway
> _______________________________________________
> Findbugs-discuss mailing list
> Findbugs-discuss@...
> https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

Re: Ignored return values

by Frank Jensen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Will this not lead to very frequent use of CheckReturnValue? How about a
"CheckAllReturnValues" at the class-level?

However, in my case the ignored return value could also have been found
using another pattern.

    String findIt() {
        String it = null;
        if (true) {
            x.getIt();
        }
        return it;
    }

Or even shorter:

    String findIt() {
        String it = null;

        return it;
    }

That is, returning a variable that is gaurranteed to be null.

Is this pattern a better FindBugs candidate?


Best Regards

Frank


On Wed, 2008-05-28 at 11:23 -0400, Bill Pugh wrote:

> If you apply the annotation  
> edu.umd.cs.findbugs.annotations.CheckReturnValue, or
> javax.annotation.CheckReturnValue (from the JSR-305 reference  
> implementation),
> FindBugs will report this.
>
> We aren't going to try to guess which methods should have their return  
> value checked,
> at least not and generate the standard correctness warning. We might  
> possibly generate a dodgy code warning.
>
> Bill
>
>
>
> On May 28, 2008, at 6:15 AM, Frank Jensen wrote:
>
> > Hello,
> >
> > FindBugs detects ignored return values from known methods:
> >
> > "hei".substring(1);//Reports: H C RV ... ignores return value
> >
> >
> > However, it does not seem to detect ignored return values from my own
> > methods:
> >
> > myObject.getIt();  //Reports nothing
> >
> > Would it be a good idea to make a more general rule about ignored  
> > return
> > values? Some times the returned value is of no interest, but perhaps  
> > it
> > is possible to detect when they probably are. For instance if
> >
> > 1. The called method have no (detectable) side effects
> > 2. The called method is a getter
> >
> >
> > Best Regards,
> >
> > Frank Jensen
> > Oslo, Norway
> > _______________________________________________
> > Findbugs-discuss mailing list
> > Findbugs-discuss@...
> > https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss
>
_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

Re: Ignored return values

by John Penix :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Frank,

How is always returning null related to not checking the return value?

John

On Thu, May 29, 2008 at 12:09 AM, Frank Jensen <frank.jensen@...> wrote:

> Will this not lead to very frequent use of CheckReturnValue? How about a
> "CheckAllReturnValues" at the class-level?
>
> However, in my case the ignored return value could also have been found
> using another pattern.
>
>    String findIt() {
>        String it = null;
>        if (true) {
>            x.getIt();
>        }
>        return it;
>    }
>
> Or even shorter:
>
>    String findIt() {
>        String it = null;
>
>        return it;
>    }
>
> That is, returning a variable that is gaurranteed to be null.
>
> Is this pattern a better FindBugs candidate?
>
>
> Best Regards
>
> Frank
>
>
> On Wed, 2008-05-28 at 11:23 -0400, Bill Pugh wrote:
>> If you apply the annotation
>> edu.umd.cs.findbugs.annotations.CheckReturnValue, or
>> javax.annotation.CheckReturnValue (from the JSR-305 reference
>> implementation),
>> FindBugs will report this.
>>
>> We aren't going to try to guess which methods should have their return
>> value checked,
>> at least not and generate the standard correctness warning. We might
>> possibly generate a dodgy code warning.
>>
>>       Bill
>>
>>
>>
>> On May 28, 2008, at 6:15 AM, Frank Jensen wrote:
>>
>> > Hello,
>> >
>> > FindBugs detects ignored return values from known methods:
>> >
>> > "hei".substring(1);//Reports: H C RV ... ignores return value
>> >
>> >
>> > However, it does not seem to detect ignored return values from my own
>> > methods:
>> >
>> > myObject.getIt();  //Reports nothing
>> >
>> > Would it be a good idea to make a more general rule about ignored
>> > return
>> > values? Some times the returned value is of no interest, but perhaps
>> > it
>> > is possible to detect when they probably are. For instance if
>> >
>> > 1. The called method have no (detectable) side effects
>> > 2. The called method is a getter
>> >
>> >
>> > Best Regards,
>> >
>> > Frank Jensen
>> > Oslo, Norway
>> > _______________________________________________
>> > Findbugs-discuss mailing list
>> > Findbugs-discuss@...
>> > https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss
>>
> _______________________________________________
> Findbugs-discuss mailing list
> Findbugs-discuss@...
> https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss
>
_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

Re: Ignored return values

by Bill Pugh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't think that methods that always return null is a particularly  
useful bug pattern. There are a number of methods that are simply  
defined as

        { return null ; }

But we might be able to extract a pattern from:

>    String findIt() {
>        String it = null;
>        if (true) {
>            x.getIt();
>        }
>        return it;
>    }

Let me think about it a bit.

Bill

_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

Re: Ignored return values

by Frank Jensen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

&�gN�j���שzw^�����ޮ('�����޶�罩nzf�q��z�^q�e�x&z�hv���������Y@�+]�ا�'��"��n�)j�^�|(�Waj�)�y�.��k��^�)���x�� ��{e�ȭ�*޶��x'�Yb��޶����jg���kz۫�)�j��z�Z�+�\���[&zYl�)i�����Z��vZ/z�,z+b��nu�E���:t�m4�Nv�u�O4�M�YO�p��^!�'��b�Kajٞ���Z��pk++z۫�{��+���˥j�r�ǟ�V����N�y��j{�m��~g���l��j���je�ן�w�j�޶���e�pzh����i�^��������Z�׫���+k�x�wH�+k�x"��X������"�޶���޶g��)�i�.�+Zn+A�Y

Parent Message unknown Re: Ignored return values

by Frank Jensen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

&�gN�j���שzw^�����ޮ('�����޶�罩nzf�q��z�^q�e�x&z�hv���������Y@�+]�ا�'��"��n�)j�^�|(�Waj�)�y�.��k��^�)���x�� ��{e�ȭ�*޶��x'�Yb��޶����jg���kz۫�)�j��z�Z�+�\���[&zYl�)i�����Z��vZ/z�,z+b��nu�E���.�$y�b��!i�!j����ޝ��x)���zk%j�m�g�����:t�m4�Nv�u�O4�M�YO�p��^!�'��b�Kajٞ���Z��pk++z۫�{��+���˥j�r�ǟ�V����N�y��j{�m��~g���l��j���je�ן�w�j�޶���e�pzh����i�^��������Z�׫���+k�x�wH�+k�x"��X������"�޶���޶g��)�i�.�+Zn+A�Y
LightInTheBox - Buy quality products at wholesale price