Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 185010 - [69cat] Bogus hint for "Pointless bitwise expression"
[69cat] Bogus hint for "Pointless bitwise expression"
Status: VERIFIED FIXED
Product: java
Classification: Unclassified
Component: Hints
6.x
All All
: P2 (vote)
: 7.0
Assigned To: Jan Lahoda
issues@java
69patch1-verified
:
: 187214 187854 188099 188273 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-04-26 14:13 UTC by swpalmer
Modified: 2010-07-08 04:54 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
:


Attachments
Test case demonstrates the bug as described in comments. (342 bytes, text/x-java)
2010-07-07 17:06 UTC, david_cogen
Details
screenshot from NB 6.9.1 (60.49 KB, image/png)
2010-07-08 04:51 UTC, Martin Fousek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description swpalmer 2010-04-26 14:13:26 UTC
Product Version = NetBeans IDE 6.9 Beta (Build 201004200117)
Operating System = Windows 7 version 6.1 running on x86
Java; VM; Vendor = 1.6.0_20
Runtime = Java HotSpot(TM) Client VM 16.3-b01

NB 6.9 is marking a bitwise operation as "pointless" when it is useful and necessary.
See comment in example code below.

import java.nio.ByteBuffer;


public class TestBitwiseExpression {
    ByteBuffer buffer = ByteBuffer.allocate(256);

    public int get8BitUnsignedValue() {
        // The 'and' with 255 is needed to promote the signed byte to an integer without sign extension
        // But NB 6.9 is flagging the operation as "pointless"
        return buffer.get(0) & 255;
    }

    public static void main(String [] args) {
        TestBitwiseExpression test = new TestBitwiseExpression();
        test.buffer.put((byte)0xff);
        System.out.println("unsigned value is "+test.get8BitUnsignedValue());
    }
}
Comment 1 johnco3 2010-06-01 17:12:37 UTC
// mask off the XYZ & 1 bits (bits 0-3)
int unpackedData =
((aRawBytes[0] & 0xf0) << 24)|    // <-- this line causes prob
((aRawBytes[1] & 0xfe) << 20)|
((aRawBytes[2] & 0xfe) << 13)|
((aRawBytes[3] & 0xfe) << 6) |
((aRawBytes[4] & 0xfe) >>> 1);
if (((aRawBytes[0] & 0x01) != 0) && // <-- also here                ((aRawBytes[1] & 0x01) == 0) &&
((aRawBytes[2] & 0x01) == 0) &&
((aRawBytes[3] & 0x01) == 0) &&
((aRawBytes[3] & 0x01) == 0)) {
Comment 2 Jan Lahoda 2010-06-08 15:06:40 UTC
*** Bug 187214 has been marked as a duplicate of this bug. ***
Comment 3 Jan Lahoda 2010-06-09 10:03:26 UTC
Fixed in trunk:
http://hg.netbeans.org/jet-main/rev/7ae50ebca759
Comment 4 Peter Pis 2010-06-09 14:51:30 UTC
Verified.

Product Version: NetBeans IDE Dev (Build 100609-3434882e3270)
Java: 1.6.0_18; Java HotSpot(TM) Client VM 16.0-b13
System: Linux version 2.6.31-22-generic running on i386; UTF-8; en_US (nb)
Comment 5 Quality Engineering 2010-06-10 06:05:57 UTC
Integrated into 'main-golden', will be available in build *201006100001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/7ae50ebca759
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #185010: when trying to evaluate arithmetic expression, make sure the root tree of the expression is also checked against accepted kinds.
Comment 6 rbalada 2010-06-16 09:54:27 UTC
For porting into release691 repository, I would like to ask for advice.

The changeset [1] updates file [2]. Unfortunately the file [2] does not exist in release691 repository [3]. I would like to ask for recommendation how to proceed. I have got two options:

#1 I can backport also changeset [4] for issue 186347 [5] and then backport the original changeset [1] for this issue (185010).

#2 I can do minimal backport of the changeset [1] for this issue (185010), ignoring the change in file [2].


If you recommend solution #1, I need you to add 6.9.1_CANDIDATE keyword to the issue 186347 [5] and request a verification of the bugfix.


References:
[1] http://hg.netbeans.org/main/rev/7ae50ebca759
[2] java.hints/test/unit/src/org/netbeans/modules/java/hints/ArithmeticUtilitiesTest.java
[3] http://hg.netbeans.org/release691/file/tip/java.hints/test/unit/src/org/netbeans/modules/java/hints/ArithmeticUtilitiesTest.java
[4] http://hg.netbeans.org/main/rev/d7f5369e419d
[5] http://netbeans.org/bugzilla/show_bug.cgi?id=186347
Comment 7 Jan Lahoda 2010-06-17 12:24:57 UTC
Sorry for late answer. I have marked bug #186347 as a 6.9.1. candidate too, but merging the test is not very important IMO - the change in ArithmeticUtilities.java is much more important.
Comment 8 rbalada 2010-06-17 14:27:23 UTC
Transplanted main #7ae50ebca759 to release691 #2d38eeec5c54
Comment 9 Jan Lahoda 2010-06-28 06:44:16 UTC
*** Bug 187854 has been marked as a duplicate of this bug. ***
Comment 10 Jan Lahoda 2010-06-29 11:23:38 UTC
*** Bug 188099 has been marked as a duplicate of this bug. ***
Comment 11 Jan Lahoda 2010-07-02 17:15:55 UTC
*** Bug 188273 has been marked as a duplicate of this bug. ***
Comment 12 Martin Fousek 2010-07-07 14:29:27 UTC
Verified in NetBeans IDE 6.9.1 Dev (Build 201007062301).
Comment 13 david_cogen 2010-07-07 17:06:30 UTC
Created attachment 100659 [details]
Test case demonstrates the bug as described in comments.
Comment 14 david_cogen 2010-07-07 17:11:34 UTC
This may not be the same issue but maybe it is. See my test Test.java. There is a warning at line 5 and 9, but not lines 6, 7, and 8, so it appears to be dependent on the array index 0.

The tooltip text says "pointless bitwise expression" but when I use Alt-enter to see the actions, the default action is "Zero constant should be removed", which is not the same thing at all! And if I tell it to go ahead, the resulting expression:
  
  int b0 = 0x0F;

has a completely different meaning!
Comment 15 Martin Fousek 2010-07-08 04:51:50 UTC
Created attachment 100677 [details]
screenshot from NB 6.9.1
Comment 16 Martin Fousek 2010-07-08 04:53:47 UTC
As you can see in image attached by myself, it's really fixed in NetBeans 6.9.1. This fix isn't accessible for NB 6.9 so please just wait for 6.9.1 release - it will solve your troubles. 

Marking as fixed again.
Comment 17 Martin Fousek 2010-07-08 04:54:36 UTC
Verified for NetBeans IDE 6.9.1 Dev (Build 201007062301) again.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo