NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

NB Hints documentation - unbalanced arrays

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Developers
View previous topic :: View next topic  
Author Message
theshadow27



Joined: 25 Mar 2009
Posts: 41

PostPosted: Mon Feb 13, 2012 5:40 am    Post subject: NB Hints documentation - unbalanced arrays Reply with quote

The Wiki ( http://wiki.netbeans.org/Java_Hints ) was last updated for 6.9. There are many new hints with no explanation as to their purpose.

I know we can disable them, but somebody added them for a reason. For example, this one I can not figure out for the life of me:

"Unbalanced read/write with arrays" => "The array is only read from, never written to"
(provided by hints/bugs/Unbalanced.java)

This is triggered in a utility class with a static final array declaration for hexadecimal encoding:
Code:
private static final char[] DIGITS = "0123456789ABCDEF".toCharArray();


If it is declared as
Code:
private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

there is no warning. Perhaps this is a bug in the hints, in which case I can report it in bugzilla, but my question still stands:

Why is it bad to only read from an array? (/why isn't the documentation up to date)
Back to top
mkozeny



Joined: 28 May 2013
Posts: 3

PostPosted: Tue May 28, 2013 9:04 am    Post subject: Reply with quote

It just usually means you forgot something, like a variable which is written to but never read. I am using NetBeans Dev Build 20130521 and this hint is appearing both for
Code:

private static final char[] DIGITS = "0123456789ABCDEF".toCharArray();


and
Code:

private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
Back to top
theshadow27



Joined: 25 Mar 2009
Posts: 41

PostPosted: Tue May 28, 2013 11:58 am    Post subject: Reply with quote

mkozeny wrote:
It just usually means you forgot something, like a variable which is written to but never read.


That is the intent of the hint (actually, I was referring to the opposite hint, read from but not written to) but it was malfunctioning. The code posted above (almost 4 years ago!) was functional, and the array was both written to and used. In java.lang.String.toCharArray method,

Code:

    /**
     * Converts this string to a new character array.
     *
     * @return  a newly allocated character array whose length is the length
     *          of this string and whose contents are initialized to contain
     *          the character sequence represented by this string.
     */
    public char[] toCharArray() {
        // Cannot use Arrays.copyOf because of class initialization order issues
        char result[] = new char[value.length];
        System.arraycopy(value, 0, result, 0, value.length);
        return result;
    }


The array is clearly written to by System.arraycopy, thus the hint was incorrectly firing.

mkozeny wrote:
I am using NetBeans Dev Build 20130521 and this hint is appearing both


Interesting, I have been using 7.3 (201302132200) for a while now and this seems to have been fixed. I will check the dev build, it might be a regression.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Developers All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


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