ZipException: zip END header not found in java-9

陌路散爱 提交于 2020-01-03 05:04:07

问题


util.zip.ZipException: zip END header not found
exception when try to load javafx fxml view in java-9.

Details
My Application is a Javafx(uses fxml view) which is built and compiled using java-8(jdk-8 64-bit) and accessed as a WebStart with jre-9(64-bit).
Webpages(xhtml) are loaded and rendered in this javafx application.

Also note that
There are already two similar bugs reported (ie. JDK-8170276, JDK-8172872) and
these two bugs mentioned that the issue is not reproducible with latest java-9
but reproducible only with earlier java-9 ea build version.

But in my case, im using latest java-9(9.0.4 version) and
its always reproducible.

Problem
When i try to load fxml popup after login, get below exceptions.

java.util.zip.ZipException: zip END header not found
at java.base/java.util.zip.ZipFile$Source.zerror(Unknown Source)
at java.base/java.util.zip.ZipFile$Source.findEND(Unknown Source)
at java.base/java.util.zip.ZipFile$Source.initCEN(Unknown Source)
at java.base/java.util.zip.ZipFile$Source.<init>(Unknown Source)
at java.base/java.util.zip.ZipFile$Source.get(Unknown Source)
at java.base/java.util.zip.ZipFile.<init>(Unknown Source)
at java.base/java.util.zip.ZipFile.<init>(Unknown Source)
at java.base/java.util.jar.JarFile.<init>(Unknown Source)
at java.base/sun.net.www.protocol.jar.URLJarFile.<init>(Unknown Source)
at java.base/sun.net.www.protocol.jar.URLJarFile.<init>(Unknown Source)
at java.base/sun.net.www.protocol.jar.URLJarFile$1.run(Unknown Source)
at java.base/sun.net.www.protocol.jar.URLJarFile$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/sun.net.www.protocol.jar.URLJarFile.retrieve(Unknown Source)
at java.base/sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source)
at java.base/sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
at java.base/sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
at jdk.deploy@9.0.1/com.sun.deploy.net.protocol.jar.DeployURLConnection.connect(Unknown Source)
at jdk.deploy@9.0.1/com.sun.deploy.net.protocol.jar.DeployURLConnection.getInputStream(Unknown Source)
at java.base/java.net.URL.openStream(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader.load(Unknown Source)
at client.FxmlWrapper.initialize(FxmlWrapper.java:57)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Suppressed: java.nio.file.NoSuchFileException: C:\Users\user\AppData\Local\Temp\jar_cache8046747560626483610.tmp
    at java.base/sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
    at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
    at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
    at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source)
    at java.base/sun.nio.fs.AbstractFileSystemProvider.delete(Unknown Source)
    at java.base/java.nio.file.Files.delete(Unknown Source)
    ... 22 common frames omitted

Request if anyone could help on this issue,would be grateful.
Many Thanks.

Although this is not the full code, but this is the code for showing fxml popup which throws "java.util.zip.ZipException: zip END header not found" exceptions in java-9, but in java-8 works fine.

PopupAction.java

public class PopupAction  
{  
public PopupAction()
{
    super();
}

public void showPopup()
{
    CountDownLatch latch = new CountDownLatch(1);
    Platform.runLater(
            new PopupHandler(latch, "testMsg", "testTitle", "testButtonText"));
    try
    {
        latch.await();
    }
    catch(InterruptedException localInterruptedException)
    {

        Thread.currentThread().interrupt();
    }
}
}

PopupHandler.java

public class PopupHandler implements Runnable
{


private CountDownLatch latch;

private String message;

private String title;

private String buttonText;

public PopupHandler(CountDownLatch latch,
        String message, String title, String buttonText)
{

    this.latch = latch;
    this.message = message;
    this.title = title;
    this.buttonText = buttonText;
}

@Override
public void run()
{
    try
    {
            Stage stage = new Stage(StageStyle.UTILITY);
            Parent root;

                stage.initModality(Modality.APPLICATION_MODAL);
                stage.setResizable(false);
                FXMLViewLoader fXMLViewLoader = new FXMLViewLoader("/fxmlView/warningPopup.fxml");
                root = fXMLViewLoader.getView();

                Scene scene = new Scene(root, 400, 110);
                scene.setFill(Color.TRANSPARENT);
                stage.setScene(scene);
                stage.setResizable(false);
                stage.setTitle(this.title);
                stage.initOwner(Application.getOwnerWindow());
                this.localAtomicBoolean.set(true);
                stage.setAlwaysOnTop(true);
                stage.showAndWait();
    }
    catch(Exception e)
    {
         e.printStackTrace();
    }
    finally
    {
        this.latch.countDown();
    }
}
}

FXMLViewLoader.java

   public final class FXMLViewLoader
   {
private FXMLLoader loader;

public FXMLViewLoader(String fxmlName)
{
    super();
    initialize(fxmlName);
}

private void initialize(String fxmlName)
{
    final URL resource = getResourceURL(fxmlName);
    this.loader = new FXMLLoader(resource);

    try
    {
        this.loader.load();
    }
    catch(Exception e)
    {
       e.printStackTrace();
    }
}

protected URL getResourceURL(String fxmlName)
{
    return this.getClass().getResource(fxmlName);
}


public Parent getView()
{
    return this.loader.getRoot();
}

}

来源:https://stackoverflow.com/questions/48402012/zipexception-zip-end-header-not-found-in-java-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!