Certain apps will stop working under Oracle JRE

Despite Excelsior JET is a compliant Java SE VM, our engineering team used to receive complaints like:

My app works fine under Sun JVM and does not work after compilation with Excelsior JET. Please fix the bug.

For the truth to be told, some (popular) Java components are written so as to work only with certain Java implementations. I believe it’s a bad practice that will strike back, sooner or later. Here goes an example.

Back in 2007, a user submitted the following bug report:

I have written a program which just uses XStream (xstream-1.1.3.jar) to create the XML tag for a final class variable in my program. I am able to execute directly using the JVM on my system.

Then I tried to compile to native EXE with Excelsior JET 4.8 and got the following Error:

Exception in thread “main”
com.thoughtworks.xstream.converters.reflection.ObjectAccessException: Invalid final field xmltest.Main.theValue

We inspected the code in the XStream library that provoked throwing the exception and, to our big surprise, found the following:

private boolean canUseSun14ReflectionProvider() {
return (isSun() || isApple() || isHPUX() || isIBM() || isBlackdown()) && is14() && loadClass("sun.misc.Unsafe") != null;
}

Well, it proved that we are not on the “white list”! By the way, the Java SE implementation by SAP was also affected by this issue. I must say that since the time we revealed the problem, we repeatedly bumped into it in different Java applications.

One drop of poison infects the whole tun of wine.

Got tired of receiving the complaints, we finally made a trick. The checks if the VM is “trustworthy” are implemented as follows:

private static boolean isSun() {
return System.getProperty("java.vm.vendor").indexOf("Sun") != -1;
}

We changed the value of java.vm.vendor from "Excelsior LLC" to "Sun Java Licensee - Excelsior LLC". Everything went well and we had a rest… for some time.

Guess what will happen when the value of java.vm.vendor in the HotSpot VM turns to "Oracle Corporation".

;)

Categories: Excelsior JET, Java

3 Responses

  1. Aleksey Says:

    So, instead of telling users to get their code fixed, you’re trying to cover up the application issue, making the obviously incorrect code to work well, thus essentially reinforcing the bad style you’re trying to beat with this post?

  2. Vitaly Mikheev Says:

    Dear colleague,

    This and some other posts are warnings for Java developers that using features not enforced by the Java spec is a bad practice. It was clearly stated in this post

    For the truth to be told, some (popular) Java components are written so as to work only with certain Java implementations. I believe it?s a bad practice that will strike back, sooner or later.

    Note, however, that the code of third-party components used by the application is not always under developer’s control. In general, we are reluctant to implement such workarounds but making things work is sometimes more important from the business perspective.

    Take care,
    –Vitaly

  3. Vitaly Mikheev Says:

    Aha! Sun to Oracle rebranding has commenced and …Eclipse IDE failed to start. The following rollback has fixed the problem.

    Long live “Sun Microsystems”!