This is an automated email from the ASF dual-hosted git repository.
pauls pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new 71cf760 FELIX-6430: fallback to builtin url handlers if we can't
reflect on unsave
71cf760 is described below
commit 71cf7607ef3cf2ee4ce3f4efef0d0f5e87db43fb
Author: Karl Pauls <[email protected]>
AuthorDate: Tue Jun 15 09:33:56 2021 +0200
FELIX-6430: fallback to builtin url handlers if we can't reflect on unsave
---
framework/pom.xml | 3 +
.../org/apache/felix/framework/URLHandlers.java | 30 ++++++++-
.../framework/URLHandlersStreamHandlerProxy.java | 77 ++++++++++------------
main/pom.xml | 3 +
4 files changed, 66 insertions(+), 47 deletions(-)
diff --git a/framework/pom.xml b/framework/pom.xml
index fe19053..1d435e0 100644
--- a/framework/pom.xml
+++ b/framework/pom.xml
@@ -125,6 +125,9 @@
osgi.service;objectClass:List<String>="org.osgi.service.packageadmin.PackageAdmin",
osgi.service;objectClass:List<String>="org.osgi.service.startlevel.StartLevel"
</Provide-Capability>
+ <Add-opens>
+ java.base/java.net java.base/sun.net.www.protocol.file
java.base/sun.net.www.protocol.ftp java.base/sun.net.www.protocol.http
java.base/sun.net.www.protocol.https java.base/sun.net.www.protocol.jar
java.base/sun.net.www.protocol.jmod java.base/sun.net.www.protocol.mailto
java.base/sun.net.www.protocol.jrt java.base/jdk.internal.loader
java.base/java.security
+ </Add-opens>
</instructions>
</configuration>
</plugin>
diff --git
a/framework/src/main/java/org/apache/felix/framework/URLHandlers.java
b/framework/src/main/java/org/apache/felix/framework/URLHandlers.java
index 548a68e..af4cb5c 100644
--- a/framework/src/main/java/org/apache/felix/framework/URLHandlers.java
+++ b/framework/src/main/java/org/apache/felix/framework/URLHandlers.java
@@ -116,8 +116,16 @@ class URLHandlers implements URLStreamHandlerFactory,
ContentHandlerFactory
m_streamPkgs = (pkgs.equals(""))
? DEFAULT_STREAM_HANDLER_PACKAGE
: pkgs + "|" + DEFAULT_STREAM_HANDLER_PACKAGE;
- m_loaded = (null != URLHandlersStreamHandlerProxy.class) &&
- (null != URLHandlersContentHandlerProxy.class) && (null !=
URLStreamHandlerService.class) && new URLHandlersStreamHandlerProxy(null, null)
!= null;
+ boolean loaded;
+ try
+ {
+ loaded = (null != URLHandlersStreamHandlerProxy.class) &&
+ (null != URLHandlersContentHandlerProxy.class) && (null !=
URLStreamHandlerService.class) && new URLHandlersStreamHandlerProxy(null, null)
!= null;
+ }
+ catch (Throwable e) {
+ loaded = false;
+ }
+ m_loaded = loaded;
}
private void init(String protocol, URLStreamHandlerFactory factory)
@@ -537,12 +545,28 @@ class URLHandlers implements URLStreamHandlerFactory,
ContentHandlerFactory
handler = getBuiltInStreamHandler(protocol,
(m_streamHandlerFactory != this) ? m_streamHandlerFactory : null);
+ if (handler == null && isJVM(protocol))
+ {
+ return null;
+ }
// If built-in content handler, then create a proxy handler.
return addToCache(m_streamHandlerCache, protocol,
- new URLHandlersStreamHandlerProxy(protocol, m_secureAction,
+ URLHandlersStreamHandlerProxy.wrap(protocol, m_secureAction,
handler, getFromCache(m_protocolToURL, protocol)));
}
+ private boolean isJVM(String protocol)
+ {
+ return protocol.equals("file") ||
+ protocol.equals("ftp") ||
+ protocol.equals("http") ||
+ protocol.equals("https") ||
+ protocol.equals("jar") ||
+ protocol.equals("jmod") ||
+ protocol.equals("mailto") ||
+ protocol.equals("jrt");
+ }
+
/**
* <p>
* This is a method implementation for the <tt>ContentHandlerFactory</tt>
diff --git
a/framework/src/main/java/org/apache/felix/framework/URLHandlersStreamHandlerProxy.java
b/framework/src/main/java/org/apache/felix/framework/URLHandlersStreamHandlerProxy.java
index 7ad09da..561b032 100644
---
a/framework/src/main/java/org/apache/felix/framework/URLHandlersStreamHandlerProxy.java
+++
b/framework/src/main/java/org/apache/felix/framework/URLHandlersStreamHandlerProxy.java
@@ -71,54 +71,35 @@ public class URLHandlersStreamHandlerProxy extends
URLStreamHandler
static {
SecureAction action = new SecureAction();
- try
- {
- EQUALS = URLStreamHandler.class.getDeclaredMethod("equals",
- new Class[]{URL.class, URL.class});
- action.setAccesssible(EQUALS);
- GET_DEFAULT_PORT =
URLStreamHandler.class.getDeclaredMethod("getDefaultPort",
- (Class[]) null);
- action.setAccesssible(GET_DEFAULT_PORT);
- GET_HOST_ADDRESS = URLStreamHandler.class.getDeclaredMethod(
- "getHostAddress", new Class[]{URL.class});
- action.setAccesssible(GET_HOST_ADDRESS);
- HASH_CODE = URLStreamHandler.class.getDeclaredMethod(
- "hashCode", new Class[]{URL.class});
- action.setAccesssible(HASH_CODE);
- HOSTS_EQUAL = URLStreamHandler.class.getDeclaredMethod(
- "hostsEqual", new Class[]{URL.class, URL.class});
- action.setAccesssible(HOSTS_EQUAL);
- OPEN_CONNECTION = URLStreamHandler.class.getDeclaredMethod(
- "openConnection", new Class[]{URL.class});
- action.setAccesssible(OPEN_CONNECTION);
- SAME_FILE = URLStreamHandler.class.getDeclaredMethod(
- "sameFile", new Class[]{URL.class, URL.class});
- action.setAccesssible(SAME_FILE);
- TO_EXTERNAL_FORM = URLStreamHandler.class.getDeclaredMethod(
- "toExternalForm", new Class[]{URL.class});
- action.setAccesssible(TO_EXTERNAL_FORM);
- }
- catch (Exception ex)
- {
- throw new RuntimeException(ex.getMessage(), ex);
- }
- Method open_connection_proxy = null;
- Class[] url_proxy_class = null;
+ EQUALS = reflect(action, "equals",
+ new Class[]{URL.class, URL.class});
+ GET_DEFAULT_PORT = reflect(action, "getDefaultPort",
+ (Class[]) null);
+ GET_HOST_ADDRESS = reflect(action, "getHostAddress", new
Class[]{URL.class});
+ HASH_CODE = reflect(action, "hashCode", new Class[]{URL.class});
+ HOSTS_EQUAL = reflect(action, "hostsEqual", new Class[]{URL.class,
URL.class});
+ OPEN_CONNECTION = reflect(action, "openConnection", new
Class[]{URL.class});
+ SAME_FILE = reflect(action, "sameFile", new Class[]{URL.class,
URL.class});
+ TO_EXTERNAL_FORM =reflect(action, "toExternalForm", new
Class[]{URL.class});
+
+ URL_PROXY_CLASS = new Class[]{URL.class, java.net.Proxy.class};
+ OPEN_CONNECTION_PROXY = reflect(action, "openConnection",
URL_PROXY_CLASS);
+ }
+
+ private static Method reflect(SecureAction action, String name, Class...
classes)
+ {
try
{
- url_proxy_class = new Class[]{URL.class, java.net.Proxy.class};
- open_connection_proxy = URLStreamHandler.class.getDeclaredMethod(
- "openConnection", url_proxy_class);
- action.setAccesssible(open_connection_proxy);
+ Method method = URLStreamHandler.class.getDeclaredMethod(name,
+ classes);
+ action.setAccesssible(method);
+ return method;
}
- catch (Throwable ex)
+ catch (Throwable t)
{
- open_connection_proxy = null;
- url_proxy_class = null;
+ return null;
}
- OPEN_CONNECTION_PROXY = open_connection_proxy;
- URL_PROXY_CLASS = url_proxy_class;
}
private final Object m_service;
@@ -146,6 +127,14 @@ public class URLHandlersStreamHandlerProxy extends
URLStreamHandler
m_builtInURL = null;
}
+ static URLStreamHandler wrap(String protocol, SecureAction action,
URLStreamHandler builtIn, URL builtInURL)
+ {
+ return ((EQUALS == null) || (GET_DEFAULT_PORT == null) ||
+ (GET_HOST_ADDRESS == null) || HASH_CODE == null || HOSTS_EQUAL
== null ||
+ (OPEN_CONNECTION == null) || (OPEN_CONNECTION_PROXY == null)
|| (SAME_FILE == null) ||
+ (TO_EXTERNAL_FORM == null)) && builtIn != null ? builtIn : new
URLHandlersStreamHandlerProxy(protocol, action, builtIn, builtInURL);
+ }
+
//
// URLStreamHandler interface methods.
//
@@ -389,7 +378,7 @@ public class URLHandlersStreamHandlerProxy extends
URLStreamHandler
if (m_builtInURL != null)
{
// However, if we are on gnu/classpath we have to pass the
handler directly
- // because the hidden feature is not there. Funnily, the
workaround to pass
+ // because the hidden feature is not there. Funnily, the
workaround to
// pass the handler directly doesn't work on sun as their
handler detects
// that it is not the same as the one inside the url and
throws an exception
// Luckily it doesn't do that on gnu/classpath. We detect
that we need to
@@ -417,7 +406,7 @@ public class URLHandlersStreamHandlerProxy extends
URLStreamHandler
else
{
// We don't have a url with a built-in handler for this
but still want to create
- // the url with the buil-in handler as we could find one
now. This might not
+ // the url with the built-in handler as we could find one
now. This might not
// work for all handlers on sun but it is better then
doing nothing.
test = m_action.createURL(url, spec, (URLStreamHandler)
svc);
}
diff --git a/main/pom.xml b/main/pom.xml
index e84ed78..61ce638 100644
--- a/main/pom.xml
+++ b/main/pom.xml
@@ -143,6 +143,9 @@
<Private-Package>org.apache.felix.main.*</Private-Package>
<Export-Package>!org.osgi.service.log, !org.osgi.service.obr,
org.osgi.*</Export-Package>
<Import-Package>!*</Import-Package>
+ <Add-opens>
+ java.base/java.net java.base/sun.net.www.protocol.file
java.base/sun.net.www.protocol.ftp java.base/sun.net.www.protocol.http
java.base/sun.net.www.protocol.https java.base/sun.net.www.protocol.jar
java.base/sun.net.www.protocol.jmod java.base/sun.net.www.protocol.mailto
java.base/sun.net.www.protocol.jrt java.base/jdk.internal.loader
java.base/java.security
+ </Add-opens>
</instructions>
</configuration>
</plugin>