You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by Sandro Martini <sa...@gmail.com> on 2009/09/03 15:38:16 UTC

Other small things

Hi, others little things, just seen (this time) with FindBugs:

- HashMap.java:122 Nullcheck of map at line 124 of value previously dereferenced
    public HashMap(Map<K, V> map) {
        this(Math.max((int)((float)map.getCount() /
DEFAULT_LOAD_FACTOR) + 1, DEFAULT_CAPACITY));

        if (map != null) {
=> we can move at the start of the method the check for not null, or
drop it (from the bottom). Suggestions ?

- ArrayList.java:453 org.apache.pivot.wtk.TreeView$BranchHandler
doesn't override org.apache.pivot.collections.ArrayList.equals(Object)
... could be right, are we sure it's overidden in TreeView$BranchHandler ?


- Dead local store: mainly to ensure that there aren't fields not
handled in these classes, or handled in a wrong way ...

Drawing: bounds is not used after calculation, is it really needed ?
        public void regionUpdated(Canvas canvas, int x, int y, int
width, int height) {
            Bounds bounds = new Bounds(0, 0, Drawing.this.width,
Drawing.this.height);
            bounds = bounds.intersect(new Bounds(x, y, width, height));
            imageListeners.regionUpdated(Drawing.this, x, y, width, height);
        }

TerraActivityIndicatorSkin: increment is not used after calculation
            final double increment = (2 * Math.PI) / 360 * 30;

TerraPanoramaSkin: scrollTop  and scrollLeft are not used after
calculation ...change the assignment moving one line over and use the
new value in the set, instead of the related max ?
            int scrollTop = panorama.getScrollTop();
            int maxScrollTop = getMaxScrollTop();
            if (scrollTop > maxScrollTop) {
                panorama.setScrollTop(maxScrollTop);
                scrollTop = maxScrollTop;
            }

            int scrollLeft = panorama.getScrollLeft();
            int maxScrollLeft = getMaxScrollLeft();
            if (scrollLeft > maxScrollLeft) {
                panorama.setScrollLeft(maxScrollLeft);
                scrollLeft = maxScrollLeft;
            }




- and finally, some other Comparator that doesn't implement
Serializable: TreeNodeComparator, TableView, and some others (few)


Bye

Re: Other small things

Posted by Sandro Martini <sa...@gmail.com>.
Ok, bur for the others, what do you think ?

Re: Other small things

Posted by Greg Brown <gk...@mac.com>.
> - and finally, some other Comparator that doesn't implement
> Serializable: TreeNodeComparator, TableView, and some others (few)

You can ignore this one. We have already verified that these  
comparators do not need to be serializable.


Re: Other small things

Posted by Greg Brown <gk...@mac.com>.
>>> TerraPanoramaSkin: scrollTop  and scrollLeft are not used after
>> Ah, I see - the warning is just saying that the variable is only  
>> used once
>> (same as above). This is intentional. I often do this to assist in
>> debugging. You can ignore these.
> If you want I could change in a way to keep the variable (for example
> to help in debugging as you said), and drop the warning, like this: ok
> ?
>
> //                panorama.setScrollTop(maxScrollTop);
> //                scrollTop = maxScrollTop;
>                scrollTop = maxScrollTop;
>                panorama.setScrollTop(scrollTop);

Thanks, but I think we should leave it as-is.


Re: Other small things

Posted by Sandro Martini <sa...@gmail.com>.
Hi,

>>       if (map != null) {
> We'll just drop it. The call to this() has to be the first line in the constructor.
Ok, I'll wait your commit ...

> I believe the bounds values were supposed to be used in the call to regionUpdated(). Fixed.
Ok, I'll wait your commit ...

> That's odd - it *is* actually used after the calculation, on line 94.
Uh, it's true ... I didn't looked some line under in the code :-) ...

>> TerraPanoramaSkin: scrollTop  and scrollLeft are not used after
> Ah, I see - the warning is just saying that the variable is only used once
> (same as above). This is intentional. I often do this to assist in
> debugging. You can ignore these.
If you want I could change in a way to keep the variable (for example
to help in debugging as you said), and drop the warning, like this: ok
?

//                panorama.setScrollTop(maxScrollTop);
//                scrollTop = maxScrollTop;
                scrollTop = maxScrollTop;
                panorama.setScrollTop(scrollTop);


Bye

Re: Other small things

Posted by Greg Brown <gk...@mac.com>.
> - HashMap.java:122 Nullcheck of map at line 124 of value previously  
> dereferenced
>    public HashMap(Map<K, V> map) {
>        this(Math.max((int)((float)map.getCount() /
> DEFAULT_LOAD_FACTOR) + 1, DEFAULT_CAPACITY));
>
>        if (map != null) {
> => we can move at the start of the method the check for not null, or
> drop it (from the bottom). Suggestions ?

We'll just drop it. The call to this() has to be the first line in the  
constructor.

> - Dead local store: mainly to ensure that there aren't fields not
> handled in these classes, or handled in a wrong way ...
>
> Drawing: bounds is not used after calculation, is it really needed ?
>        public void regionUpdated(Canvas canvas, int x, int y, int
> width, int height) {
>            Bounds bounds = new Bounds(0, 0, Drawing.this.width,
> Drawing.this.height);
>            bounds = bounds.intersect(new Bounds(x, y, width, height));
>            imageListeners.regionUpdated(Drawing.this, x, y, width,  
> height);
>        }

I believe the bounds values were supposed to be used in the call to  
regionUpdated(). Fixed.

> TerraActivityIndicatorSkin: increment is not used after calculation
>            final double increment = (2 * Math.PI) / 360 * 30;

That's odd - it *is* actually used after the calculation, on line 94.

> TerraPanoramaSkin: scrollTop  and scrollLeft are not used after
> calculation ...change the assignment moving one line over and use the
> new value in the set, instead of the related max ?
>            int scrollTop = panorama.getScrollTop();
>            int maxScrollTop = getMaxScrollTop();
>            if (scrollTop > maxScrollTop) {
>                panorama.setScrollTop(maxScrollTop);
>                scrollTop = maxScrollTop;
>            }
>
>            int scrollLeft = panorama.getScrollLeft();
>            int maxScrollLeft = getMaxScrollLeft();
>            if (scrollLeft > maxScrollLeft) {
>                panorama.setScrollLeft(maxScrollLeft);
>                scrollLeft = maxScrollLeft;
>            }

Ah, I see - the warning is just saying that the variable is only used  
once (same as above). This is intentional. I often do this to assist  
in debugging. You can ignore these.