You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2022/01/03 07:30:50 UTC

[maven-mvnd] branch master updated: Fix url cache (fixes #532 and #527)

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git


The following commit(s) were added to refs/heads/master by this push:
     new 06fa4fd  Fix url cache (fixes #532 and #527)
06fa4fd is described below

commit 06fa4fd227479ff697f4c05e872da34ac6129b0a
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Jan 3 08:30:41 2022 +0100

    Fix url cache (fixes #532 and #527)
---
 .../java/org/mvndaemon/mvnd/client/DefaultClient.java     |  1 +
 .../main/java/org/mvndaemon/mvnd/common/MavenDaemon.java  |  5 -----
 .../src/main/java/org/mvndaemon/mvnd/daemon/Server.java   | 15 +++++++--------
 3 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java b/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java
index be2b9c4..4b24437 100644
--- a/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java
+++ b/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java
@@ -151,6 +151,7 @@ public class DefaultClient implements Client {
                 " --add-opens java.base/java.io=ALL-UNNAMED"
                         + " --add-opens java.base/java.lang=ALL-UNNAMED"
                         + " --add-opens java.base/java.util=ALL-UNNAMED"
+                        + " --add-opens java.base/sun.net.www.protocol.jar=ALL-UNNAMED"
                         + " --add-opens java.base/sun.nio.fs=ALL-UNNAMED");
     }
 
diff --git a/common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java b/common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java
index 63ca04e..d94779f 100644
--- a/common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java
+++ b/common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java
@@ -15,7 +15,6 @@
  */
 package org.mvndaemon.mvnd.common;
 
-import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -26,10 +25,6 @@ import java.util.stream.Stream;
 public class MavenDaemon {
 
     public static void main(String[] args) throws Exception {
-        // Disable URL caching so that  the JVM does not try to cache resources
-        // loaded from jars that are built by a previous run
-        new File("txt").toURI().toURL().openConnection().setDefaultUseCaches(false);
-
         final Path mvndHome = Environment.MVND_HOME.asPath();
         URL[] classpath = Stream.concat(
                 /* jars */
diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java b/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java
index 1d6974f..ae8b88f 100644
--- a/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java
+++ b/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java
@@ -168,14 +168,7 @@ public class Server implements AutoCloseable, Runnable {
                     try {
                         registry.close();
                     } finally {
-                        try {
-                            socket.close();
-                        } finally {
-                            if (!noDaemon) {
-                                clearCache("sun.net.www.protocol.jar.JarFileFactory", "urlCache");
-                                clearCache("sun.net.www.protocol.jar.JarFileFactory", "fileCache");
-                            }
-                        }
+                        socket.close();
                     }
                 }
             }
@@ -193,6 +186,7 @@ public class Server implements AutoCloseable, Runnable {
             cache.clear();
         } catch (Throwable t) {
             // ignore
+            LOGGER.warn("Error clearing cache {}.{}", clazzName, fieldName, t);
         }
     }
 
@@ -263,6 +257,11 @@ public class Server implements AutoCloseable, Runnable {
             }
         } catch (Throwable t) {
             LOGGER.error("Error reading request", t);
+        } finally {
+            if (!noDaemon) {
+                clearCache("sun.net.www.protocol.jar.JarFileFactory", "urlCache");
+                clearCache("sun.net.www.protocol.jar.JarFileFactory", "fileCache");
+            }
         }
     }