Мы переносим наш старый код, фактически довольно старый, на Java 11. У меня возникают проблемы при компиляции одного из классов.Пример кода:
package XXXX;
import java.lang.ref.*;
import sun.security.action.*;
import java.security.*;
import java.io.*;
class Converters
{
private static Object lock;
private static String converterPackageName;
private static String defaultEncoding;
public static final int BYTE_TO_CHAR = 0;
public static final int CHAR_TO_BYTE = 1;
private static final String[] converterPrefix;
private static SoftReference[] classCache;
static /* synthetic */ Class class$sun$io$Converters;
private static String getConverterPackageName() {
final String converterPackageName = Converters.converterPackageName;
if (converterPackageName != null) {
return converterPackageName;
}
String converterPackageName2 = AccessController.doPrivileged((PrivilegedAction<String>)new GetPropertyAction("file.encoding.pkg"));
if (converterPackageName2 != null) {
Converters.converterPackageName = converterPackageName2;
}
else {
converterPackageName2 = "sun.io";
}
return converterPackageName2;
}
private static Class getConverterClass(final int n, final String s) throws UnsupportedEncodingException {
String aliasName = null;
if (!s.equals("ISO8859_1")) {
if (s.equals("8859_1")) {
aliasName = "ISO8859_1";
}
else if (s.equals("ISO8859-1")) {
aliasName = "ISO8859_1";
}
else if (s.equals("646")) {
aliasName = "ASCII";
}
else {
aliasName = CharacterEncoding.aliasName(s);
}
}
if (aliasName == null) {
aliasName = s;
}
try {
return Class.forName(getConverterPackageName() + "." + Converters.converterPrefix[n] + aliasName);
}
catch (ClassNotFoundException ex) {
throw new UnsupportedEncodingException(aliasName);
}
}
private static Object newConverter(final String s, final Class clazz) throws UnsupportedEncodingException {
try {
return clazz.newInstance();
}
catch (InstantiationException ex) {
throw new UnsupportedEncodingException(s);
}
catch (IllegalAccessException ex2) {
throw new UnsupportedEncodingException(s);
}
}
static Object newConverter(final int n, final String s) throws UnsupportedEncodingException {
final Class converterClass;
synchronized (Converters.lock) {
converterClass = getConverterClass(n, s);
}
return newConverter(s, converterClass);
}
private static Class getDefaultConverterClass(final int n) {
boolean b = false;
final SoftReference softReference = Converters.classCache[n];
if (softReference != null) {
final Class clazz = softReference.get();
if (clazz != null) {
return clazz;
}
Converters.classCache[n] = null;
}
String defaultEncoding = Converters.defaultEncoding;
if (Converters.defaultEncoding != null) {
b = true;
}
else {
defaultEncoding = AccessController.doPrivileged((PrivilegedAction<String>)new GetPropertyAction("file.encoding"));
if (defaultEncoding != null) {
Converters.defaultEncoding = defaultEncoding;
b = true;
}
else {
defaultEncoding = "ISO8859_1";
}
}
Class clazz2;
try {
clazz2 = getConverterClass(n, defaultEncoding);
if (b) {
Converters.classCache[n] = new SoftReference(clazz2);
}
}
catch (UnsupportedEncodingException ex) {
try {
clazz2 = getConverterClass(n, "ISO8859_1");
}
catch (UnsupportedEncodingException ex2) {
throw new InternalError("Cannot find default " + Converters.converterPrefix[n] + " converter class");
}
}
return clazz2;
}
static Object newDefaultConverter(final int n) {
final Class defaultConverterClass;
synchronized (Converters.lock) {
defaultConverterClass = getDefaultConverterClass(n);
}
try {
return newConverter("", defaultConverterClass);
}
catch (UnsupportedEncodingException ex) {
throw new InternalError("Cannot instantiate default converter class " + defaultConverterClass.getName());
}
}
static /* synthetic */ Class class$(final String s) {
try {
return Class.forName(s);
}
catch (ClassNotFoundException ex) {
throw new NoClassDefFoundError(ex.getMessage());
}
}
static {
Converters.lock = ((Converters.class$sun$io$Converters == null) ? (Converters.class$sun$io$Converters = class$("sun.io.Converters")) : Converters.class$sun$io$Converters);
Converters.converterPackageName = null;
Converters.defaultEncoding = null;
converterPrefix = new String[] { "ByteToChar", "CharToByte" };
Converters.classCache = new SoftReference[2];
}
}
При компиляции с использованием javac Converter.java
появляется следующее сообщение об ошибке:
import sun.security.action.*;
^
(package sun.security.action is declared in module java.base, which does not export it to the unnamed module)
Converters.java:47: error: cannot find symbol
aliasName = CharacterEncoding.aliasName(s);
^
symbol: variable CharacterEncoding
location: class Converters
Converters.java:85: error: incompatible types: Object cannot be converted to Class
final Class clazz = softReference.get();
^
Note: Converters.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Converters.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
Я пытался экспортировать это с помощью --add--export
java.base/sun.security=All-UNNAMED
, это все ещевыдает ошибку.
Любая помощь?Также хотелось бы знать, есть ли другой способ удалить этот старый унаследованный код новым.