I have the following code to retrieve the default URLStreamHandlers
for http and https which works in Java 8 by accessing the static package scoped method URL.getURLStreamHandler()
:
private URLStreamHandler getURLStreamHandler(String protocol) {
try {
Method method = URL.class.getDeclaredMethod("getURLStreamHandler", String.class);
method.setAccessible(true);
return (URLStreamHandler) method.invoke(null, protocol);
} catch (Exception e) {
logger.warning("could not access URL.getUrlStreamHandler");
return null;
}
}
Will this still be possible in Java 9 with jigsaw or will modifying the visibility in this way be prohibited?