JDK-5027269 : (process) System.getenv() throws ExceptionInInitializerError in Netscape 4.x
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2004-04-06
  • Updated: 2006-09-27
  • Resolved: 2004-09-14
Related Reports
Duplicate :  
Relates :  
Description
Name: atR10251			Date: 04/06/2004


The problem comes up when System.getenv() is called from an applet inside Netscape 4.x on Solaris.

Run this applet to reproduce it:

-----------------------------------
import java.applet.Applet;

public class MyApp extends Applet {
    public void start() {
        System.getenv("DISPLAY");
    }
}
-----------------------------------

The following exception will be thrown:

java.lang.ExceptionInInitializerError
        at java.lang.System.getenv(System.java:795)
        at MyApp.start(MyApp.java:5)
        at sun.applet.AppletPanel.run(AppletPanel.java:394)
        at java.lang.Thread.run(Thread.java:570)
Caused by: java.lang.NullPointerException
        at java.lang.String.<init>(String.java:486)
        at java.lang.ProcessEnvironment$Variable.valueOf(ProcessEnvironment.java:157)
        at java.lang.ProcessEnvironment.<clinit>(ProcessEnvironment.java:58)
        ... 4 more

Despite the fact that this method is deprecated we use it in AWT code because of the absence
of any alternative. You may look at the bug 4979996 to see this necessity.
Regarding this problem, we found a workaround so that we avoid calling System.getenv() in applets,
but still need it in applications.

So, I file this bug just to show the problem.
======================================================================

Comments
EVALUATION Extremely interesting. I know of no reason why one would get a null pointer exception. The only thing I can think of is an environ that is highly unusual, but my inspection of the code for ProcessEnvironment gives no clue how the behavior could ever happen. BTW, as of 1.5, System.getenv(String) is no longer deprecated. How could it be that this behavior only occurs in netscape 4, not mozilla or appletviewer? Is the JVM invoked with strange flags, affecting GC perhaps? ###@###.### 2004-04-08 After much effort, I managed to get a working Netscape 4 with a Tiger plugin. Netscape 4.79 did not work together with Tiger's demo applets, but On Xiaobin Lu's advice, switched to Netscape Navigator 4.76, which indeed worked well. I found I couldn't run applets using the <applet> tag - those would invoke the 1.1.5 jvm builtin to Netscape Navigator 4. Instead I converted the applet using HtmlConverter. The resulting applet, when executing System.getenv("DISPLAY"), generates a SecurityException, which is expected. When adding a RuntimePermission "getenv.*" to ~/.java.policy, then System.getenv("DISPLAY") is successful and returns the correct answer. The original cause of the problem, which still looks like it might be a Tiger bug, is a deep mystery. ###@###.### 2004-04-09 Xiaobin pointed out that the bug has only been seen on solaris-x86, so I tried again. I installed netscape 4.76 on "foundation.sfbay", a solaris-x86 machine, in the same way as I did on solaris-sparc, but on solaris-x86 I couldn't even get any of the plugin demos to run. More specifically, I made a symlink libjavaplugin.so -> /java/re/jdk/1.5.0/promoted/latest/binaries/solaris-i586/jre/plugin/i386/ns4/libjavaplugin.so* and made file:///java/re/jdk/1.5.0/promoted/latest/binaries/solaris-i586/demo/plugin/applets.html my "Home Page" and tried clicking on the various demos on that page. They all caused netscape to die without any error message or core file. There's essentially no solaris-x86-specific code in java.lang. Given how flaky the Netscape4+Java combination is, maybe the submitter's bug is due to some weird memory corruption or some strange bug in the JVM. After chatting with some of the JVM folks, it appears that the String(byte[]) constructor could throw a NullPointerException if there is corruption in JVM data structures, not just if the argument to the constructor is null. So my current theory is to blame Netscape. ###@###.### 2004-04-09 This is now perfectly explained by the analysis of 5101311: NullPointerException thrown when environment contains strings without `=' Probably Netscape was inserting bogus values into the environment in some situations. ###@###.### 2004-09-14
14-09-2004