从 1.6 jdk 到 11 jdk 的迁移代码问题 sun.net.www.protocol.file
Migration code from 1.6 jdk to 11 jdk problem with sun.net.www.protocol.file
我在迁移使用 sun.net.*
和 sun.net.www.protocol.file.FileURLConnection
的旧代码时遇到问题
Ant 无法在 jdk 11 上构建项目,因为 FileURLConnection
来自基础包的内部版本 8/9 class。 FileURLCOnnection 用于检查返回的 class 实例,因此我需要很好的想法如何在不破坏逻辑的情况下替换此片段(下面的片段)。
connection instanceof FileURLConnection
for (URL url = null; resources.hasMoreElements()
&& ((url = resources.nextElement()) != null); ) {
try {
connection = url.openConnection();
if (connection instanceof JarURLConnection) {
checkJarFile((JarURLConnection) connection, pckgname,
classes);
} else if (connection instanceof FileURLConnection) {
try {
checkDirectory(
new File(URLDecoder.decode(url.getPath(),
"UTF-8")), pckgname, classes);
} catch (final UnsupportedEncodingException ex) {
throw new ClassNotFoundException(
pckgname
+ " does not appear to be a valid package (Unsupported encoding)",
ex);
}
} else
throw new ClassNotFoundException(pckgname + " ("
+ url.getPath()
+ ") does not appear to be a valid package");
} catch (final IOException ioex) {
throw new ClassNotFoundException(
"IOException was thrown when trying to get all resources for "
+ pckgname, ioex);
}
}
您应该可以替换:
connection instanceof FileURLConnection
作者:
"file".equals(url.getProtocol())
我在迁移使用 sun.net.*
和 sun.net.www.protocol.file.FileURLConnection
的旧代码时遇到问题
Ant 无法在 jdk 11 上构建项目,因为 FileURLConnection
来自基础包的内部版本 8/9 class。 FileURLCOnnection 用于检查返回的 class 实例,因此我需要很好的想法如何在不破坏逻辑的情况下替换此片段(下面的片段)。
connection instanceof FileURLConnection
for (URL url = null; resources.hasMoreElements()
&& ((url = resources.nextElement()) != null); ) {
try {
connection = url.openConnection();
if (connection instanceof JarURLConnection) {
checkJarFile((JarURLConnection) connection, pckgname,
classes);
} else if (connection instanceof FileURLConnection) {
try {
checkDirectory(
new File(URLDecoder.decode(url.getPath(),
"UTF-8")), pckgname, classes);
} catch (final UnsupportedEncodingException ex) {
throw new ClassNotFoundException(
pckgname
+ " does not appear to be a valid package (Unsupported encoding)",
ex);
}
} else
throw new ClassNotFoundException(pckgname + " ("
+ url.getPath()
+ ") does not appear to be a valid package");
} catch (final IOException ioex) {
throw new ClassNotFoundException(
"IOException was thrown when trying to get all resources for "
+ pckgname, ioex);
}
}
您应该可以替换:
connection instanceof FileURLConnection
作者:
"file".equals(url.getProtocol())