incubator-yoko-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mosur Ravi, Balaji" <br...@iona.com>
Subject RE: Static fields and intialization
Date Mon, 23 Oct 2006 12:46:40 GMT
Hi,

The checkstyle check should allow for these kinds of checks but since
our core module had so many files, we didn't have time to go through
them & fix them. Can you log a jira item for this & we can take care of
it smaller chunks...

- Balaji

-----Original Message-----
From: Dain Sundstrom [mailto:dain@iq80.com] 
Sent: Friday, October 20, 2006 7:21 PM
To: yoko-dev@incubator.apache.org
Subject: Static fields and intialization

I just committed a fix to a bug caused by static field initialization  
(YOKO-196).  The bug was cause by a static initalizer calling a  
static method which accessed a static field.  I was getting a  
NullPointerException because the static field was null because the  
static field was declared after the initializer.  For example:

public class Test {
     static {
       foo();
     }

     private static final Object bar = new Object();

     private static void foo() {
        System.out.println(bar);
     }

     public static void main(String[] args) throws Exception {
         foo();
     }
}

This problem type of problem is very difficult to find and is easily  
avoided by putting all field declarations at the top of the file  
followed by any static initializers.

What do you think of changing the coding standards to have all fields  
at the top of the file?

-dain

Mime
View raw message