Skip to content

Commit

Permalink
fixed a classloader leak
Browse files Browse the repository at this point in the history
  • Loading branch information
oehme committed Dec 18, 2014
1 parent d2764ee commit 825bb09
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.lang.reflect.Field;
import java.net.URLClassLoader;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.xtend.core.compiler.batch.XtendBatchCompiler;
Expand All @@ -16,6 +18,7 @@
import com.google.inject.Inject;

public class FixedXtendBatchCompiler extends XtendBatchCompiler {
private static final Logger LOG = Logger.getLogger(FixedXtendBatchCompiler.class.getCanonicalName());

@Inject
private ProcessorInstanceForJvmTypeProvider annotationProcessorFactory;
Expand All @@ -31,7 +34,8 @@ public boolean compile() {
if (classLoader instanceof Closeable) {
try {
classLoader.close();
} catch (IOException ignored) {
} catch (IOException e) {
LOG.log(Level.WARNING, "Could not close a classloader", e);
}
}
}
Expand All @@ -46,9 +50,11 @@ protected void installJvmTypeProvider(ResourceSet resourceSet,
classLoaders.add(classLoader);
try {
Field classLoaderField = ProcessorInstanceForJvmTypeProvider.class.getDeclaredField("classLoader");
classLoaderField.setAccessible(true);
URLClassLoader annotationClassLoader = (URLClassLoader) classLoaderField.get(annotationProcessorFactory);
classLoaders.add(annotationClassLoader);
} catch (Exception ignored) {
} catch (Exception e) {
LOG.log(Level.WARNING, "Could not close a classloader", e);
}
}
}

0 comments on commit 825bb09

Please sign in to comment.