Static final bug tools?

Looking for a tool that can detect this:
static final int[] FOO = {1,2,3,4}
FOO[3] = 99;
So basically something that can look through the jar or class files and see if a final reference is being dereferenced and has that being used as an lvalue. Not that that case is always going to be a bug, but if a tool could print out where that occured it would make it way easier to track down the cases that are. Is there any such tool?

well guess i was wrong, i thought u couldnt compile
something that tries to asign a value to a static
final variableYou cannot, but that is not what's happening in that example. That code modifies the object referred to by a final variable, which is permitted. What's not allowed is to reassign null or a different reference to the variable. It's the variable that's final, not the object.

Similar Messages

  • NX-OS release note V.S. bug tool

    Hi Everyone:
    I confused with bug tool and release note.
    For example:
    I use bug tool to check nexus 5596UP -- 5.2(1)N1(7) --> got bug CSCug49968
    https://tools.cisco.com/bugsearch/bug/CSCug49968
    but this bug can not be found in the release note Open Caveats
    http://www.cisco.com/c/en/us/td/docs/switches/datacenter/nexus5000/sw/release/notes/Rel_5_2_1_N1_1/Nexus5000_Release_Notes_5_2_1_N1.html#pgfId-416411
    which one is correct??
    thanks.

    Hi Sam & Christine,
    I'm just wondering if the BST look and feel we are seeing
    since the weekend is the "final" product? If so, I'm going to need
    a tutorial because I can't get it to work the way I thought it
    was supposed to for the life of me
    If I try to search a Product Family>Product Name and go through all the search steps
    to get to Communications Manager 9.1 and search "DRF" it seems to populate
    the related bugs, which is good. But there doesn't seem to be a way to move to
    Communications Manager 8.6, or any other, without going through the whole process
    again. My understanding was that one of the main points of the new version of BST
    was the ability to move between version releases seamlessly??
    If I just put Cisco Unified Communications Manager (CallManager) in the Product Name
    box then 44,335 bugs are displayed and the Releases box is grayed out so I can't define
    a specific version
    Maybe I'm just missing something here which would be no surprise.
    Cheers!
    Rob
    "go easy...step lightly...stay free " 
    - The Clash

  • Static final buffer passed into FilterOutputStream.write(byte[])

    Greetings,
    My team is using a custom subclass of FilterOutputStream to XOR some bytes with a key before writing them to an underlying OutputStream. We have never had problems with it until we started testing with Java 1.4.x -- where we noticed that some optimizations had been made to GZIPOutputStream to write the GZIP header out at once using a static final buffer to hold the header.
    The problem seems to be that this header, although marked as static final, can still be changed when it is passed to our custom FilterOutputStream's write(byte[] b) method. For speed, we are XORing the bytes in place in the byte[] and then writing it directly back out. So every time we write the header with the same key, the static final byte[] that holds the header in GZIPOutputStream changes from its XORed to cleartext equivalent, and back.
    My question is this: should this be considered a bug in the SDK, or a bug in our code? Maybe I'm looking in the wrong place, but I can't find any documentation that specifies what can and can't be done with a byte[] that is passed into the write(byte[]) method of an OutputStream.
    Any input is appreciated.
    Regards,
    Mike Pontillo

    Mike,
    Need some code here to clarify. Are you saying that
    the original final static (constant) changes?
    You've got to be careful when you talk about passing a
    byte[], which can't be done, of course. You are
    passing a reference to a byte[]. Using the reference,
    the bytes can be copied. There aren't any restrictions
    on what can be done to the copy.
    and also, if you have final array, then only that arrays'
    reference is final, but the content of array may change
    as well as when that array wasn't static.Yes, I understand this. Thank you for your replies. FilterOutputStream.write(byte[]) of course takes a reference to a byte[]. We are overloading this to be something like:
    public void write(byte[] b) {
       for(int i = 0 ; i < b.length ; i++) {
          b[i] = foo(b);
    out.write(b);
    i.e. we modify the array inside the method rather than making a copy and writing out the copy.
    This hasn't been a problem until Java 1.4.x -- now GZIPOutputStream passes a private static final byte[] (reference of course) into write(byte[]) in OutputStream. So when our overloaded write(byte[]) method gets called in FilterOutputStream and code similar to the above runs, the private static final reference to a byte[] is overwritten in the java.util.zip.GZIPOutputStream class. This was a change sometime between 1.3 and 1.4, I believe. From the J2SDK 1.4.1_02 source:
         * Writes GZIP member header.
        private final static byte[] header = {
            (byte) GZIP_MAGIC,                // Magic number (short)
            (byte)(GZIP_MAGIC >> 8),          // Magic number (short)
            Deflater.DEFLATED,                // Compression method (CM)
            0,                                // Flags (FLG)
            0,                                // Modification time MTIME (int)
            0,                                // Modification time MTIME (int)
            0,                                // Modification time MTIME (int)
            0,                                // Modification time MTIME (int)
            0,                                // Extra flags (XFLG)
            0                                 // Operating system (OS)
        private void writeHeader() throws IOException {
            out.write(header);
        }As you can see, they are passing a private static final reference to a byte array into somebody's untrusted method (ours). =)
    Due to this issue we have to change our code so that it makes a copy of these bytes rather than changing them in the method. Now I'm wondering if this should be considered a bug in Java or not -- does changing bytes like this violate the general contract of an Input/Output stream? It at least seems like a bad idea for encapsulation purposes since anyone can change these bytes in the GZIPOutputStream class. We had previously assumed that if they were writing these bytes to an output stream they didn't care about them any more, which is the case 99.9% of the time in our experience.

  • Static final in (Class or Interface)

    Hello Friends ,
    What is the difference in having a public static final variable in an class and having the same kind of
    declarations in an Interface ?
    Does the interface is better or having it in a class ?
    Thanks in Advance,
    -S

    shyamnambiar wrote:
    But I'm not clear . you mean to say its all the same .It does not make any difference ?The only difference that it makes (and that might be an important difference) is what you communicate with your design an intention.
    Constants should usually be placed within their context since that's where they are going to be used, and that's where developers will look. It's more common to place the constants in the class that they are related to. They should not be placed in an empty final class just because you want to group constants. You should also avoid placing constants in an interface just because you then can implement that interface to "get hold of" the constants.
    Kaj

  • Declaring public static final variables in jsp?

    The question is in the title...
    I know this is not a jsp forum, but some people here might know if it's possible or not.
    If yes, how to declare them and how to access them from other jsp pages?
    Thx

    If you need that, you definitely do too much work in your JSPs. You should do all your work in Servlets (or Actions if you're using Struts or something similar).
    Your JSPs should only do the presentation.
    Remember that JSPs are not classes (they are compiled into classes internally, but you don't have direct access to those).
    If you absolutely need such a public static final field that you want to access from several JSPs, just define it in a Class and reference that class from your JSPs.

  • Instantiation of static final objects

    Is there a problem with coding the following?:
    class A {
    public static final A static_final_a_obj = new A ( B.static_final_b_obj );
    private B b;
    public A ( B b ) {
    this.b = b;
    class B {
    public static final B static_final_b_obj = new B ( A.static_final_a_obj );
    private A a;
    public B ( A a ) {
    this.a = a;
    I put log messages in each of the constructors to see if it would cause an infinite loop, but it doesn't seem to. The question is 'why'.. :) How can either of the static final objects ever be fully instantiated?

    Exactly. It is not executed infinitely.
    class A {
    public static final A static_final_a_obj = new A ( B.static_final_b_obj );
    private B b;
    public A ( B b ) {
    System.out.println(" A Cons");
    this.b = b;
    public static void main(String args[]) {
         System.out.println("A");
    Output:
    B Cons
    A Cons
    A
    class B {
    public static final B static_final_b_obj = new B ( A.static_final_a_obj );
    private A a;
    public B ( A a ) {
    System.out.println(" B Cons");
    this.a = a;
    public static void main(String args[]) {
         System.out.println("B");
    Output:
    A Cons
    B Cons
    B
    Edited by: prajeshps on Sep 18, 2007 1:51 PM

  • ERROR: serializable class HelloComponent does not declare a static final

    Hi everyone! I'm sorry but I'm a newbie to Java and I'm having some, I assume, basic problems learning to compile and run with javac. Here is my code:
    import javax.swing.* ;
    import java.awt.* ;
    public class MyJava {
    * @param args
    public static void main(String[] args)
    // TODO Auto-generated method stub
    JFrame frame = new JFrame( "HelloJava" ) ;
    HelloComponent hello = new HelloComponent() ;
    frame.add( hello ) ;
    frame.setSize( 300, 300 ) ;
    frame.setVisible( true ) ;
    class HelloComponent extends JComponent
    public void paintComponent( Graphics g )
    g.drawString( "Hello Java it's me!", 125, 95 ) ;
    And here is the error:
    1. WARNING in HelloJava.java
    (at line 20)
    class HelloComponent extends JComponent {
    ^^^^^^^^^^^^^^
    The serializable class HelloComponent does not declare a static final serialVersionUID field of type long
    ANY HELP WOULD BE GREAT! THANKS! =)

    Every time I extend GameLoop, it gives me the warning
    serializable class X does not declare a static final serialVersionUID field of type long
    This is just a warning. You do not need to fix this because the class you are writing will never be serialized by the gaming engine. If you really want the warning to go away, add the code to your class:
    static final long serialVersionUID=0;

  • Trying to acces the value of a public static final int using reflection

    -Java 6
    -Windows XP
    -Signed Applet
    doing the following:
    Class.forName(classname).getField(code).getInt(null);
    is giving me the error:
    java.lang.IllegalAccessException: Class com.cc.applet.util.ServiceConfiguration can not access a member of class com.cc.util.error.codes.SendMessageErrorCodes with modifiers "public static final"
         at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
         at java.lang.reflect.Field.doSecurityCheck(Unknown Source)
         at java.lang.reflect.Field.getFieldAccessor(Unknown Source)
         at java.lang.reflect.Field.getInt(Unknown Source)
    I'm not understanding why it can't access the value of the field. Any help would be great.
    Edited by: zparticle on Oct 17, 2007 11:07 PM

    stefan.schulz wrote:
    oebert, you are right. Good one.
    I actually think that, in this case, the message is misleading. The current implementation of sun.reflect.Reflection.ensureMemberAccess() treats any failing access check the same. It should and could inculde better contextual information.Stefan,
    That is a good point. Did you file a RFE with Sun yet? I also think they should provide a more contextual error message in this case.
    Gili

  • Public static final Comparator String CASE_INSENSITIVE_ORDER

    in this declaration..
    public static final Comparator<String> CASE_INSENSITIVE_ORDER
    what does <String> mean?
    thanks!

    what does the Comparator do. Look at the API and you would see the following description about the compare method.
    public int compare(Object o1,
    Object o2)Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
    The implementor must ensure that sgn(compare(x, y)) == -sgn(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)
    The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.
    Finally, the implementer must ensure that compare(x, y)==0 implies that sgn(compare(x, z))==sgn(compare(y, z)) for all z.
    It is generally the case, but not strictly required that (compare(x, y)==0) == (x.equals(y)). Generally speaking, any comparator that violates this condition should clearly indicate this fact. The recommended language is "Note: this comparator imposes orderings that are inconsistent with equals."
    Now your question is about what <String> is in your declaration. It is the type of the objects which are going to be compared.

  • Constant values (public static final String) are not shown??

    This has already been posted and no body answered. Any help is appreciated.
    In web service is it possible to expose the Constants used in the application. Let say for my web service I need to pass value for Operation, possible values for this are (add, delete, update). Is it possible expose these constant values(add, delete, update) visible to client application accesssing the web service.
    Server Side:
    public static final String ADD = "ADDOPP";
    public static final String DELETE = "DELETEOPP";
    public static final String UPDATE = "UPDATEOPP";
    client Side: mywebserviceport.setOperation( mywebservicePort.ADD );
    thanks
    vijay

    Sure, you can use JAX-WS and enums.
    For example on the server:
    @WebService
    public class echo {
    public enum Status {RED, YELLOW, GREEN}
    @WebMethod
    public Status echoStatus(Status status) {
    return status;
    on the client you get.
    @WebService(name = "Echo", wsdlLocation ="..." )
    public interface Echo {
    @WebMethod
    public Status echoStatus(
    @WebParam(name = "arg0", targetNamespace = "")
    Status arg0);
    @XmlEnum
    public enum Status {
    GREEN,
    RED,
    YELLOW;
    public String value() {
    return name();
    public static Status fromValue(String v) {
    return valueOf(v);
    }

  • Help with public static final List

    I'm having a block here... I want to have a constant List, but I can't figure out how to do it so it actually contains the values I want. It's going to be a list of strings about 40 elements long. Obviously, if I didn't need the final, I'd just do List.add( ), but I need to do it right in the constructor. Thanks for the help.

    I guess the problem could be reworded, If I wantedto
    put this in a class that would never getinstantiated
    how would I initialize the List?You use a static intializer.Ah. I didn't get that out of the question. Thanks for the help.
    But here's an example:public class Foo {  
        static final java.util.List<String> list = new java.util.ArrayList<String>();
            list.add("one");
            list.add("two");
            list.add("three");
            // etc.
    }

  • Why a Constant has to be of type Static final  rather than final?

    Hi,
    I struck up with a basic doubt
    Why a Constant has to be of type Static final rather than final?
    Hoping for quick reply
    Venu.

    Hi,
    I struck up with a basic doubt
    Why a Constant has to be of type Static final rather
    than final?It doesn't have to be, but it usually makes more sense for it to be static (associated with the class) than non-static (associated with the instance). If every instance of the class will have the same value for that variable--whether it's final and a constant or not--it makes sense to make it static. There's no need for multiple copies of the same value. (And in the case of non-final variables, it can lead to incorrect program behavior if it's not static.) If each instance of the class could potentially have a different value for that variable, then it has to be non-static.

  • The serializable class SpacePainter does not declare a static final serial

    The serializable class SpacePainter does not declare a static final serialVersionUID field of type longWhat does this mean??? It appears as a warning in Eclipse but I have no idea what it is. It happens when I create a class the extends JFrame or JCompnent or JApplet. I finnally got it to stop with this:
    static final long serialVersionUID = 1;

    Because your eclipse is configured that way. You can probably filter the warning. You don't have to implement the serialVersionUID, but you should if you really serialize the exceptions.

  • 'private static final String' constants vs inline constants

    Other than source code readability and maintainability, is there any runtime benefit from declaring String constants as 'private static final' in your code? Does this effect the way the String is stored in memory in the constant pool?
    Thanks, Kevin

    I guess my question really is, is this String declared inline:
    System.out.println("some constant");treated any different internally in memory at runtime compared with this:
    System.out.println(SOME_CONSTANT);
    private static final String SOME_CONSTANT = "some constant";Since both Strings end up in the Constant Pool, how is declaring it 'static final' of any benefit in terms of performance?

  • Will declaring primitives as static final (constants) conserve memory?

    I wrote a code
    int a = flag?1:0;on which my supervisor commented that 1 and 0 should be replaced by SomeInterface.ONE (=1) and SomeInterface.ZERO (=0) respectively. The reason he gave was that since constants are static so it will conserve memory.
    Is this really true?

    First of all, this Interface for Constants anti-pattern is widely derided.
    Secondly, one of the reasons it was used in the first place was readability, not performance, and in that case constants that pertain to the meaning of that 1 and 0, and not the values, might have been understandable (e.g. SomeInterface.TRUE = 1 and SomeInterface.FALSE = 0), but definately not ONE and ZERO.
    Thirdly, memory use is the same as public static final variables (as interface constants are), have their value compiled directly into the class using them, at the point where it used, so whether a constant is used, or a literal value, the space that that class definition uses is the same. In addition, there is then an interface definition that also has those values so the memory use is more, in end effect. And, regardless, that memory space is not on the heap, which is the memory space you will be most interested in, so it has no noticeable effect on memory space either way.

Maybe you are looking for