Skip to content
Snippets Groups Projects
Commit f730c54d authored by Tomasz Grabiec's avatar Tomasz Grabiec Committed by Pekka Enberg
Browse files

java: do not mask system classes


Commit 211bb7fb introduced masking of
system classes from the isolate point of view in order to prevent
runjava dependencies form becoming visible, which might cause
conflicts if application would like to use the same classes but of
different version. Currently the dependencies include cglib and asm
which are also used by spring framework and hibernate. Making them
visible would force the applications to use our version of these
libraries, which can be older or newer than the required one.

Unfortunately this causes extension classes from jre/lib/ext to be
unavailable to the application. They are part of the system class
loader, not bootstrap. One of the side effects is that security
providers are not found (See issue #208).

This fix chooses another approach to fix the problem. Instead of
masking dependencies we move them under io.osv.* namespace so that
they will not cause conflicts. For this task I use apache plugin for
maven which automatically renames packages in our uber runjava jar.

Fixes #208.

Reviewed-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: default avatarTomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent 3cb967b4
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,31 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>net.sf.cglib</pattern>
<shadedPattern>io.osv.shade.net.sf.cglib</shadedPattern>
</relocation>
<relocation>
<pattern>org.objectweb.asm</pattern>
<shadedPattern>io.osv.shade.org.objectweb.asm</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
......@@ -60,8 +60,7 @@ public class ContextIsolator {
ClassLoader originalSystemClassLoader = getOsvClassLoader().getParent();
masterContext = new Context(originalSystemClassLoader, System.getProperties());
parentClassLoaderForIsolates = new TeeClassLoader(
new FilteringClassLoader(originalSystemClassLoader, "io.osv."));
parentClassLoaderForIsolates = originalSystemClassLoader;
installSystemPropertiesProxy();
}
......
package io.osv;
class FilteringClassLoader extends ClassLoader {
private final String allowedPrefix;
public FilteringClassLoader(ClassLoader parent, String allowedPrefix) {
super(parent);
this.allowedPrefix = allowedPrefix;
}
private boolean isClassAllowed(String name) {
return name.startsWith(allowedPrefix);
}
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if (!isClassAllowed(name)) {
throw new ClassNotFoundException(name);
}
return super.loadClass(name, resolve);
}
}
package io.osv;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
class TeeClassLoader extends ClassLoader {
private ClassLoader delegate;
public TeeClassLoader(ClassLoader delegate) {
super(null);
this.delegate = delegate;
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
return delegate.loadClass(name);
}
@Override
protected URL findResource(String name) {
return delegate.getResource(name);
}
@Override
protected Enumeration<URL> findResources(String name) throws IOException {
return delegate.getResources(name);
}
}
......@@ -81,23 +81,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testSourceDirectory>${basedir}/src/main/java/</testSourceDirectory>
<testClassesDirectory>target/classes</testClassesDirectory>
<argLine>-ea -Djava.system.class.loader=io.osv.OsvSystemClassLoader
-Djava.util.logging.manager=io.osv.jul.IsolatingLogManager
</argLine>
<systemProperties>
<property>
<name>isolates.jar</name>
<value>${io.osv:tests-isolates:jar:jar-with-dependencies}</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</project>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment