Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

RE: Subtle static initializer change in JDK 1.5: msg#00027

java.findbugs.general

Subject: RE: Subtle static initializer change in JDK 1.5

Bill,

I've posted internally to ask for more examples of this. I'll let you
know what we come up with....

Thanks.

Michael Ward

-----Original Message-----
From: Bill Pugh [mailto:pugh@xxxxxxxxxx]
Sent: Tuesday, May 08, 2007 10:28 AM
To: Ward, Michael S.
Cc: eu@xxxxxxxx; findbugs-discuss@xxxxxxxxxxxxxxxxxx
Subject: Re: [FB-Discuss] Subtle static initializer change in JDK 1.5

I thought about this a little more.

What you want to look for is:
* classes that have static initializers that make changes to the static
state of other classes
* no direct uses of the class are seen outside of the class (e.g. no
external get/put/invoke statics, or constructor invocations), but do
reference Class objects for that class.

I'd really like to have more than this one example of the bug to figure
out what will actually be needed to detect more general cases of it.

Bill

On May 8, 2007, at 8:07 AM, <Michael.S.Ward@xxxxxxxxxxxxxx> wrote:

> Eugene,
>
> I would like to build a detector for this but I'm not sure I follow
> your explanation. What methods would be stored in the database /
> annotated??
>
> Thanks,
>
> Michael Ward
>
> -----Original Message-----
> From: findbugs-discuss-bounces@xxxxxxxxxx
> [mailto:findbugs-discuss-bounces@xxxxxxxxxx] On Behalf Of Eugene
> Kuleshov
> Sent: Monday, May 07, 2007 4:53 PM
> To: findbugs-discuss@xxxxxxxxxxxxxxxxxx
> Subject: Re: [FB-Discuss] Subtle static initializer change in JDK 1.5
>
>
> It should be possible, but it will require some deep inter-method
> analysis, just to check how class value is actually used.
>
> On the other hand is quite easy to tell if class is initialized or not

> on the caller side (LDC ClassConst vs. Class.forName() call), and then

> if you could annotate methods that need explicit initialization, or
> maintain some kind of database of such methods, then inter-method
> analysis can be skipped.
>
> regards,
> Eugene
>
>
>
> Michael.S.Ward@xxxxxxxxxxxxxx wrote:
>>
>> JDK 1.5 has introduced a change to the behavior of static blocks and
>> when they are executed. I found this while testing an application for
>> 1.5 compatibility. A short discussion of this issue can be found at
>> _http://forum.java.sun.com/thread.jspa?
>> threadID=557504&messageID=27356
>> 05_
>> <http://forum.java.sun.com/thread.jspa?
>> threadID=557504&messageID=27356
>> 05>
>>
>> Below is a sample that demonstrates the impact of the change.
>> Would it
>
>> be possible for findbugs to detect something like this?? If so how
>> difficult do you think it may be to write a detector for it?? Here is

>> a link describing the work around,
>> _http://java.sun.com/j2se/1.5.0/compatibility.html_ (see #5 under
>> Incompatibilities in Java 2 Platform Standard Edition 5.0 (since
> 1.4.2)).
>>
>> Thanks for the help,
>>
>> *Michael Ward*
>>
>> import org.apache.commons.lang.enums.Enum;
>>
>> public class StaticTestEnum extends Enum {
>>
>> public static final String YES_VALUE = "YES"; public static final
>> String NO_VALUE = "NO"; public static final StaticTestEnum YES = new
>> StaticTestEnum(YES_VALUE); public static final StaticTestEnum NO =
>> new
>
>> StaticTestEnum(NO_VALUE);
>>
>> public StaticTestEnum(String s) {
>> super(s);
>> }
>> }
>>
>> import org.apache.commons.lang.enums.EnumUtils;
>>
>> public class StaticTest {
>>
>> public static void main(String[] args) { StaticTestEnum e =
>> (StaticTestEnum)EnumUtils.getEnum(StaticTestEnum.class, "YES"); if (e

>> == null) { System.out.println("Enum is null, static initializers not
>> executed -- JDK 1.5"); } else { System.out.println("Enum value is " +
>> e.toString() + ", static initializers executed -- JDK 1.4"); } } }
>>
>>
>> -------------------------------------------
>> JDK 1.5 Test
>> -------------------------------------------
>> $ which java
>> /c/jdk1.5.0_11/bin/java
>>
>> $ which javac
>> /c/jdk1.5.0_11/bin/javac
>>
>> $ javac -cp
>> "c:/projects/.maven/repository/commons-lang/jars/commons-
>> lang-2.1.jar"
>
>> *.java
>>
>> $ java -cp
>>
> "c:/projects/.maven/repository/commons-lang/jars/commons-
> lang-2.1.jar;."
>
>> StaticTest
>> Enum is null, static initializers not executed - JDK 1.5
>>
>> -------------------------------------------
>> JDK 1.4 Test
>> -------------------------------------------
>> $ which java
>> /c/j2sdk1.4.2_13/bin/java
>>
>> $ which javac
>> /c/j2sdk1.4.2_13/bin/javac
>>
>> $ javac -classpath
>> "c:/projects/.maven/repository/commons-lang/jars/commons-
>> lang-2.1.jar"
>
>> *.java
>>
>> $ java -classpath
>>
> "c:/projects/.maven/repository/commons-lang/jars/commons-
> lang-2.1.jar;."
>
>> StaticTest
>> Enum value is StaticTestEnum[YES], static initializers executed - JDK
>> 1.4
>>
>> ---------------------------------------------------------------------
>> -
>> --
>>
>> _______________________________________________
>> Findbugs-discuss mailing list
>> Findbugs-discuss@xxxxxxxxxxxxxxxxxx
>> http://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss
>>
>
> _______________________________________________
> Findbugs-discuss mailing list
> Findbugs-discuss@xxxxxxxxxxxxxxxxxx
> http://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss
>
>
>
> _______________________________________________
> Findbugs-discuss mailing list
> Findbugs-discuss@xxxxxxxxxxxxxxxxxx
> http://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss






<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
solaris.opensol...    editors.vim/200...    web.turbogears....    jakarta.ant.dev...    mathematics.max...    text.unicode.ge...    lang.ruby.core/...    xfce.announce/2...    network.centeri...    php.cvs.pear/20...    user-groups.lin...    kde.devel.quant...    file-systems.ar...    redhat.fedora.t...    apple.fink.auto...    gnome.orbit.gen...    qplus.devel/200...    culture.transpo...    video.dri.user/...    operators.nanog...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation