Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2014-08-26 13:04:52 -0400
committerIgor Fedorenko2014-08-26 13:04:52 -0400
commitf5f5fd9a272b0a4ee1ea10dd791cdac9814c97fd (patch)
tree713b50bba0c2a8b871a6106280431fd878e07bb7 /org.eclipse.m2e.core
parenta859c1054ee751ae3f52fc2a1295cc73fbc8e24b (diff)
downloadm2e-core-f5f5fd9a272b0a4ee1ea10dd791cdac9814c97fd.tar.gz
m2e-core-f5f5fd9a272b0a4ee1ea10dd791cdac9814c97fd.tar.xz
m2e-core-f5f5fd9a272b0a4ee1ea10dd791cdac9814c97fd.zip
442524 workaround jvm crash when changed jar files are reloaded
Change-Id: Id8c1ea8afb90099761726b2b930423bd29409646 Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
Diffstat (limited to 'org.eclipse.m2e.core')
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java2
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/URLConnectionCaches.java62
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java5
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java4
4 files changed, 73 insertions, 0 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java
index 82207689..84b0615f 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java
@@ -166,6 +166,8 @@ public class MavenPluginActivator extends Plugin {
new Throwable().printStackTrace();
}
+ URLConnectionCaches.disable();
+
this.bundleContext = context;
try {
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/URLConnectionCaches.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/URLConnectionCaches.java
new file mode 100644
index 00000000..633125cc
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/URLConnectionCaches.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Takari, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Takari, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.internal;
+
+import java.net.URLConnection;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Workaround for JDK bug http://bugs.java.com/view_bug.do?bug_id=6207022
+ *
+ * @since 1.6
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=442524
+ * @see http://bugs.java.com/view_bug.do?bug_id=6207022
+ */
+public final class URLConnectionCaches {
+
+ private static final Logger log = LoggerFactory.getLogger(URLConnectionCaches.class);
+
+ private static final URLConnection conn = new URLConnection(null) {
+ public void connect() {
+ }
+ };
+
+ private URLConnectionCaches() {
+ }
+
+ /**
+ * Disables caching of URLConnections by default.
+ * <p>
+ * According to JDK bug 6207022, JVM caches opened jar files, which results in JVM crashes or other unpredictable
+ * results if the jar are closed, overwritten and reopened.
+ * <p>
+ * This workaround disables URLConnection caching for all protocols, not just jar files, which may result in
+ * performance problems for other URLConnection clients. There is also no way to guarantee that other code does not
+ * reenable caching of URLConnections.
+ * <p>
+ * Longer term solution is likely two fold. First, always create unique copies of jar files passed to Maven class
+ * realms. Second, use {@link URLConnection#setUseCaches(boolean)} to false for all jar files opened by Maven and
+ * Sisu. Both require significant effort, however.
+ */
+ public static void disable() {
+ conn.setDefaultUseCaches(false);
+ }
+
+ public static void assertDisabled() {
+ if(conn.getDefaultUseCaches()) {
+ log.error("Unexpected URLConnection defaultUseCaches enabled");
+ }
+ }
+}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java
index ff7339cf..eee6de1b 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java
@@ -46,6 +46,7 @@ import org.apache.maven.project.MavenProject;
import org.eclipse.m2e.core.internal.ExtensionReader;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
+import org.eclipse.m2e.core.internal.URLConnectionCaches;
import org.eclipse.m2e.core.internal.builder.BuildResultCollector.Message;
import org.eclipse.m2e.core.internal.builder.IIncrementalBuildFramework.BuildContext;
import org.eclipse.m2e.core.internal.builder.plexusbuildapi.AbstractEclipseBuildContext;
@@ -93,6 +94,10 @@ public class MavenBuilderImpl {
public Set<IProject> build(MavenSession session, IMavenProjectFacade projectFacade, int kind,
Map<String, String> args, Map<MojoExecutionKey, List<AbstractBuildParticipant>> participants,
IProgressMonitor monitor) throws CoreException {
+
+ // 442524 safety guard
+ URLConnectionCaches.assertDisabled();
+
Collection<BuildDebugHook> debugHooks = MavenBuilder.getDebugHooks();
Set<IProject> dependencies = new HashSet<IProject>();
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
index 493d1348..874e85ce 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java
@@ -81,6 +81,7 @@ import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
import org.eclipse.m2e.core.internal.ExtensionReader;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.Messages;
+import org.eclipse.m2e.core.internal.URLConnectionCaches;
import org.eclipse.m2e.core.internal.builder.MavenBuilder;
import org.eclipse.m2e.core.internal.embedder.MavenExecutionContext;
import org.eclipse.m2e.core.internal.embedder.MavenImpl;
@@ -309,6 +310,9 @@ public class ProjectRegistryManager {
throws CoreException {
log.debug("Refreshing: {}", pomFiles); //$NON-NLS-1$
+ // 442524 safety guard
+ URLConnectionCaches.assertDisabled();
+
final DependencyResolutionContext context = new DependencyResolutionContext(pomFiles);
// safety net -- do not force refresh of the same installed/resolved artifact more than once

Back to the top