WIN-28: fix POSIX file descriptor numbering assumptions

Bryce McKinlay bryce@waitaki.otago.ac.nz
Sat Mar 2 09:58:00 GMT 2002


Adam Megacz wrote:

>Bryce McKinlay <bryce@waitaki.otago.ac.nz> writes:
>
>>How about putting the initialization of in/out/err into a native method 
>>and calling it from a static initializer, ie:
>>
>>static
>>{
>>  initNative();
>>}
>>
>
>I tried this -- unfortunately java.lang.System's <clinit> runs first,
>and it read the not-yet-initialized values out of
>FileDescriptor.{in|out|err} and crash trying to build a 'new
>PrintStream(null)'.
>

Huh? This can't happen. The language guarantees that a class is 
initialized before accessing its static fields. The only exceptions are:

- initializers which are somehow mutally dependent (they arn't in this case)
- field access from native (CNI) code, in which case an explicit 
JvInitClass() call is needed

>If you initialize to 'new FileDescriptor(getFdFOO())', the compiler
>figures out that it has to execute that code before it lets
>System.java access the variable. I don't know why this happens.
>

The compiler must execute all static initializer code before accessing a 
static field from a class. If it doesn't then there is a compiler bug.

regards

Bryce.




More information about the Java-patches mailing list