How to determine if the JVM was updated without a reboot (on Windows)?

We often get the following stack trace from Windows users:

java.lang.UnsatisfiedLinkError: sun.awt.image.ImageRepresentation.setBytePixels(IIII[BIILsun/awt/image/ByteComponentRaster;I)V at sun.awt.image.ImageRepresentation.setBytePixels(Native Method) at sun.awt.image.ImageRepresentation.setPixels(Unknown Source) at sun.awt.image.ImageDecoder.setPixels(Unknown Source) at sun.awt.image.GifImageDecoder.sendPixels(Unknown Source) at sun.awt.image.GifImageDecoder.parseImage(Native Method) at sun.awt.image.GifImageDecoder.readImage(Unknown Source) at sun.awt.image.GifImageDecoder.produceImage(Unknown Source) at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source) at sun.awt.image.ImageFetcher.fetchloop(Unknown Source) at sun.awt.image.ImageFetcher.run(Unknown Source) 

This happens when the user has updated Java, and then first tries to start our application without rebooting. Obviously, updating Java requires (like everything else on Windows) a reboot of the machine in order to return it to a usable state.

This is not an exception that we can catch, since none of our codes are in the call stack. We can handle the exception from Thread.UncaughtExceptionHandler , which we are doing now.

Instead, we would like to be able to check at startup whether we are in a need to reboot after the update, either by calling this exception directly, or by catching it, or by performing some other checks. (At present, we have no idea what even causes this ...) Does anyone know how we can do this?

+4
source share
2 answers

I'm afraid you're out of luck. There may be a registry entry that allows the OS to know that it should reboot, but it is installed only if the installer requires it. The only exception is if there is code using a DLL that would otherwise be replaced by the installer. The installation process will bring up the “Restart Required to Complete” dialog box from the OS.

I do not yet have an automatic Java update requiring a reboot of my machine. If the OS is never in the "require reboot" state, you have nothing to look for and check. The best you can do is to catch the exception and display a nice error message. I would report this problem as an error for Oracle (it will be difficult for a person to get used to it). Perhaps future updates will behave correctly.

+2
source

If you have a guarantee that you can call any code before an exception occurs, I would advise you to consider manually checking the version of Java. You never know whether the latest update will fail, but you can always check if the Java version has changed since the last run. Let it be stored somewhere in a simple way.

Then during each launch, if the version of Java has changed, you will see the information “Java is updated and my application may behave incorrectly. It is recommended that you restart and / or stop the continuation.

Sort of:

 public static void main(String[] argv) { String lastJVM = retrieveJVMversionFromLastExecution(); String currentJVM = System.getProperty("java.version"); if (!currentJVM.equals(lastJVM)) { throw new RuntimeException("New JVM. Please reboot"); } else { storeJVMversionPersistently(currentJVM); } // ... your normal operation } 
0
source

All Articles