This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 244841

Summary: Erroneous "The array is only written to, never read from" and "The assigned value is never used"
Product: java Reporter: Zom-B
Component: HintsAssignee: Svata Dedic <sdedic>
Status: RESOLVED WONTFIX    
Severity: normal    
Priority: P4    
Version: 8.0   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description Zom-B 2014-06-02 12:56:38 UTC
In the following example, I get both warnings, the former on the first occurrence of 'data' and the latter on 'dataBuffer.getData()':

"The array is only written to, never read from" and "The assigned value is never used"

When I comment out the for loop (so 'data' is actually not used), the second warning disappears, and the first stays. This is wrong, because 'data' is not written to anymore.

When I change '10000' to 'data.length', both warnings disappear.

public class Temp {
    public static void main(String[] args) {
        BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
        img.setAccelerationPriority(0);

        WritableRaster raster = img.getRaster();
        DataBufferInt dataBuffer = (DataBufferInt)raster.getDataBuffer();
        int[] data = dataBuffer.getData();

        for (int p = 0; p < 10000; p++) data[p++] = p/*something*/;
    }
}

The program works fine nontheless (the image updates as expected).
Comment 1 Svata Dedic 2014-06-06 14:07:18 UTC
The 'assigned value' warning is gone (another bug report was for that) -- the value is actually used by `data[p++]' statement.

The other warning is tough; if the array is shared / referenced from elsewhere, it may be valid only to stuff data into it, since it will be acquired and accessed by other means than just direct access through the array reference.
Comment 2 Martin Balin 2016-07-07 07:18:23 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss