mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-17 17:07:53 +00:00
6921740: Eliminate warnings from sun.io converters and allow compiling with JAVAC_MAX_WARNINGS=true
Fix sun.io converters unchecked and cast warnings produced by -Xlint:all Reviewed-by: alanb, sherman
This commit is contained in:
parent
b09ac3b7e8
commit
d7c18f0617
@ -31,7 +31,7 @@ BUILDDIR = ../..
|
||||
PACKAGE = sun.nio
|
||||
PRODUCT = sun
|
||||
|
||||
OTHER_JAVACFLAGS += -Xlint:serial -Werror
|
||||
OTHER_JAVACFLAGS += -Xlint:serial,-deprecation -Werror
|
||||
include $(BUILDDIR)/common/Defs.gmk
|
||||
|
||||
#
|
||||
|
||||
@ -113,7 +113,7 @@ public class ByteToCharUTF8 extends ByteToCharConverter {
|
||||
savedSize = 1;
|
||||
} else {
|
||||
savedSize = 2;
|
||||
savedBytes[1] = (byte)input[byteOff++];
|
||||
savedBytes[1] = input[byteOff++];
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -135,11 +135,11 @@ public class ByteToCharUTF8 extends ByteToCharConverter {
|
||||
savedSize = 1;
|
||||
} else if (byteOff + 1 >= inEnd) {
|
||||
savedSize = 2;
|
||||
savedBytes[1] = (byte)input[byteOff++];
|
||||
savedBytes[1] = input[byteOff++];
|
||||
} else {
|
||||
savedSize = 3;
|
||||
savedBytes[1] = (byte)input[byteOff++];
|
||||
savedBytes[2] = (byte)input[byteOff++];
|
||||
savedBytes[1] = input[byteOff++];
|
||||
savedBytes[2] = input[byteOff++];
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -154,10 +154,10 @@ public class ByteToCharUTF8 extends ByteToCharConverter {
|
||||
throw new MalformedInputException();
|
||||
}
|
||||
// this byte sequence is UTF16 character
|
||||
int ucs4 = (int)(0x07 & byte1) << 18 |
|
||||
(int)(0x3f & byte2) << 12 |
|
||||
(int)(0x3f & byte3) << 6 |
|
||||
(int)(0x3f & byte4);
|
||||
int ucs4 = (0x07 & byte1) << 18 |
|
||||
(0x3f & byte2) << 12 |
|
||||
(0x3f & byte3) << 6 |
|
||||
(0x3f & byte4);
|
||||
outputChar[0] = (char)((ucs4 - 0x10000) / 0x400 + 0xd800);
|
||||
outputChar[1] = (char)((ucs4 - 0x10000) % 0x400 + 0xdc00);
|
||||
outputSize = 2;
|
||||
|
||||
@ -46,7 +46,7 @@ public class CharToByteUnicode extends CharToByteConverter {
|
||||
protected int byteOrder = UNKNOWN;
|
||||
|
||||
public CharToByteUnicode() {
|
||||
String enc = (String) java.security.AccessController.doPrivileged(
|
||||
String enc = java.security.AccessController.doPrivileged(
|
||||
new sun.security.action.GetPropertyAction("sun.io.unicode.encoding",
|
||||
"UnicodeBig"));
|
||||
if (enc.equals("UnicodeBig"))
|
||||
|
||||
@ -50,11 +50,11 @@ public class CharacterEncoding {
|
||||
|
||||
private static boolean sjisIsMS932;
|
||||
|
||||
private static Map aliasTable;
|
||||
private static Map<String,String> aliasTable;
|
||||
private static volatile boolean installedAll;
|
||||
|
||||
static {
|
||||
aliasTable = new HashMap(460, 1.0f); /* MDA */
|
||||
aliasTable = new HashMap<>(460, 1.0f); /* MDA */
|
||||
|
||||
aliasTable.put("us-ascii", "ASCII");
|
||||
aliasTable.put("ascii", "ASCII");
|
||||
@ -119,11 +119,11 @@ public class CharacterEncoding {
|
||||
}
|
||||
// need to use Locale.US so we can load ISO converters in tr_TR locale
|
||||
String lower = name.toLowerCase(Locale.US);
|
||||
String val = (String) aliasTable.get(lower);
|
||||
String val = aliasTable.get(lower);
|
||||
|
||||
if (val == null && !installedAll) {
|
||||
installAll();
|
||||
val = (String) aliasTable.get(lower);
|
||||
val = aliasTable.get(lower);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
@ -131,7 +131,7 @@ public class CharacterEncoding {
|
||||
private static synchronized void installAll() {
|
||||
if (!installedAll) {
|
||||
GetPropertyAction a = new GetPropertyAction("sun.nio.cs.map");
|
||||
String map = ((String)AccessController.doPrivileged(a));
|
||||
String map = AccessController.doPrivileged(a);
|
||||
if (map != null) {
|
||||
sjisIsMS932 = map.equalsIgnoreCase("Windows-31J/Shift_JIS");
|
||||
} else {
|
||||
@ -857,9 +857,9 @@ public class CharacterEncoding {
|
||||
* Auto Detect converter.
|
||||
*/
|
||||
static String getSJISName() {
|
||||
String encodeName = (String) AccessController.doPrivileged(
|
||||
new PrivilegedAction() {
|
||||
public Object run() {
|
||||
String encodeName = AccessController.doPrivileged(
|
||||
new PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
String osName = System.getProperty("os.name");
|
||||
if (osName.equals("Solaris") || osName.equals("SunOS")){
|
||||
return "PCK";
|
||||
@ -880,9 +880,9 @@ public class CharacterEncoding {
|
||||
|
||||
|
||||
static String getEUCJPName() {
|
||||
String encodeName = (String) AccessController.doPrivileged(
|
||||
new PrivilegedAction() {
|
||||
public Object run() {
|
||||
String encodeName = AccessController.doPrivileged(
|
||||
new PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
String osName = System.getProperty("os.name");
|
||||
if (osName.equals("Solaris") || osName.equals("SunOS"))
|
||||
return "eucJP-open";
|
||||
|
||||
@ -85,10 +85,11 @@ public class Converters {
|
||||
* this code can be involved in the startup sequence it's important to keep
|
||||
* the footprint down.
|
||||
*/
|
||||
private static SoftReference[][] classCache
|
||||
= new SoftReference[][] {
|
||||
new SoftReference[CACHE_SIZE],
|
||||
new SoftReference[CACHE_SIZE]
|
||||
@SuppressWarnings("unchecked")
|
||||
private static SoftReference<Object[]>[][] classCache
|
||||
= (SoftReference<Object[]>[][]) new SoftReference<?>[][] {
|
||||
new SoftReference<?>[CACHE_SIZE],
|
||||
new SoftReference<?>[CACHE_SIZE]
|
||||
};
|
||||
|
||||
private static void moveToFront(Object[] oa, int i) {
|
||||
@ -98,28 +99,28 @@ public class Converters {
|
||||
oa[0] = ob;
|
||||
}
|
||||
|
||||
private static Class cache(int type, Object encoding) {
|
||||
SoftReference[] srs = classCache[type];
|
||||
private static Class<?> cache(int type, Object encoding) {
|
||||
SoftReference<Object[]>[] srs = classCache[type];
|
||||
for (int i = 0; i < CACHE_SIZE; i++) {
|
||||
SoftReference sr = srs[i];
|
||||
SoftReference<Object[]> sr = srs[i];
|
||||
if (sr == null)
|
||||
continue;
|
||||
Object[] oa = (Object[])sr.get();
|
||||
Object[] oa = sr.get();
|
||||
if (oa == null) {
|
||||
srs[i] = null;
|
||||
continue;
|
||||
}
|
||||
if (oa[1].equals(encoding)) {
|
||||
moveToFront(srs, i);
|
||||
return (Class)oa[0];
|
||||
return (Class<?>)oa[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Class cache(int type, Object encoding, Class c) {
|
||||
SoftReference[] srs = classCache[type];
|
||||
srs[CACHE_SIZE - 1] = new SoftReference(new Object[] { c, encoding });
|
||||
private static Class<?> cache(int type, Object encoding, Class<?> c) {
|
||||
SoftReference<Object[]>[] srs = classCache[type];
|
||||
srs[CACHE_SIZE - 1] = new SoftReference<Object[]>(new Object[] { c, encoding });
|
||||
moveToFront(srs, CACHE_SIZE - 1);
|
||||
return c;
|
||||
}
|
||||
@ -129,12 +130,12 @@ public class Converters {
|
||||
*/
|
||||
public static boolean isCached(int type, String encoding) {
|
||||
synchronized (lock) {
|
||||
SoftReference[] srs = classCache[type];
|
||||
SoftReference<Object[]>[] srs = classCache[type];
|
||||
for (int i = 0; i < CACHE_SIZE; i++) {
|
||||
SoftReference sr = srs[i];
|
||||
SoftReference<Object[]> sr = srs[i];
|
||||
if (sr == null)
|
||||
continue;
|
||||
Object[] oa = (Object[])sr.get();
|
||||
Object[] oa = sr.get();
|
||||
if (oa == null) {
|
||||
srs[i] = null;
|
||||
continue;
|
||||
@ -152,9 +153,9 @@ public class Converters {
|
||||
private static String getConverterPackageName() {
|
||||
String cp = converterPackageName;
|
||||
if (cp != null) return cp;
|
||||
java.security.PrivilegedAction pa =
|
||||
java.security.PrivilegedAction<String> pa =
|
||||
new sun.security.action.GetPropertyAction("file.encoding.pkg");
|
||||
cp = (String)java.security.AccessController.doPrivileged(pa);
|
||||
cp = java.security.AccessController.doPrivileged(pa);
|
||||
if (cp != null) {
|
||||
/* Property is set, so take it as the true converter package */
|
||||
converterPackageName = cp;
|
||||
@ -168,9 +169,9 @@ public class Converters {
|
||||
public static String getDefaultEncodingName() {
|
||||
synchronized (lock) {
|
||||
if (defaultEncoding == null) {
|
||||
java.security.PrivilegedAction pa =
|
||||
java.security.PrivilegedAction<String> pa =
|
||||
new sun.security.action.GetPropertyAction("file.encoding");
|
||||
defaultEncoding = (String)java.security.AccessController.doPrivileged(pa);
|
||||
defaultEncoding = java.security.AccessController.doPrivileged(pa);
|
||||
}
|
||||
}
|
||||
return defaultEncoding;
|
||||
@ -194,7 +195,7 @@ public class Converters {
|
||||
* encoding, or throw an UnsupportedEncodingException if no such class can
|
||||
* be found
|
||||
*/
|
||||
private static Class getConverterClass(int type, String encoding)
|
||||
private static Class<?> getConverterClass(int type, String encoding)
|
||||
throws UnsupportedEncodingException
|
||||
{
|
||||
String enc = null;
|
||||
@ -241,7 +242,7 @@ public class Converters {
|
||||
* Instantiate the given converter class, or throw an
|
||||
* UnsupportedEncodingException if it cannot be instantiated
|
||||
*/
|
||||
private static Object newConverter(String enc, Class c)
|
||||
private static Object newConverter(String enc, Class<?> c)
|
||||
throws UnsupportedEncodingException
|
||||
{
|
||||
try {
|
||||
@ -261,7 +262,7 @@ public class Converters {
|
||||
static Object newConverter(int type, String enc)
|
||||
throws UnsupportedEncodingException
|
||||
{
|
||||
Class c;
|
||||
Class<?> c;
|
||||
synchronized (lock) {
|
||||
c = cache(type, enc);
|
||||
if (c == null) {
|
||||
@ -279,9 +280,9 @@ public class Converters {
|
||||
* not yet defined, return a class that implements the fallback default
|
||||
* encoding, which is just ISO 8859-1.
|
||||
*/
|
||||
private static Class getDefaultConverterClass(int type) {
|
||||
private static Class<?> getDefaultConverterClass(int type) {
|
||||
boolean fillCache = false;
|
||||
Class c;
|
||||
Class<?> c;
|
||||
|
||||
/* First check the class cache */
|
||||
c = cache(type, DEFAULT_NAME);
|
||||
@ -325,7 +326,7 @@ public class Converters {
|
||||
* encoding cannot be determined.
|
||||
*/
|
||||
static Object newDefaultConverter(int type) {
|
||||
Class c;
|
||||
Class<?> c;
|
||||
synchronized (lock) {
|
||||
c = getDefaultConverterClass(type);
|
||||
}
|
||||
|
||||
@ -48,23 +48,23 @@ public class AbstractCharsetProvider
|
||||
|
||||
/* Maps canonical names to class names
|
||||
*/
|
||||
private Map classMap
|
||||
= new TreeMap(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
|
||||
private Map<String,String> classMap
|
||||
= new TreeMap<>(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
/* Maps alias names to canonical names
|
||||
*/
|
||||
private Map aliasMap
|
||||
= new TreeMap(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
|
||||
private Map<String,String> aliasMap
|
||||
= new TreeMap<>(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
/* Maps canonical names to alias-name arrays
|
||||
*/
|
||||
private Map aliasNameMap
|
||||
= new TreeMap(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
|
||||
private Map<String,String[]> aliasNameMap
|
||||
= new TreeMap<>(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
/* Maps canonical names to soft references that hold cached instances
|
||||
*/
|
||||
private Map cache
|
||||
= new TreeMap(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
|
||||
private Map<String,SoftReference<Charset>> cache
|
||||
= new TreeMap<>(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
private String packagePrefix;
|
||||
|
||||
@ -79,13 +79,13 @@ public class AbstractCharsetProvider
|
||||
/* Add an entry to the given map, but only if no mapping yet exists
|
||||
* for the given name.
|
||||
*/
|
||||
private static void put(Map m, String name, Object value) {
|
||||
private static <K,V> void put(Map<K,V> m, K name, V value) {
|
||||
if (!m.containsKey(name))
|
||||
m.put(name, value);
|
||||
}
|
||||
|
||||
private static void remove(Map m, String name) {
|
||||
Object x = m.remove(name);
|
||||
private static <K,V> void remove(Map<K,V> m, K name) {
|
||||
V x = m.remove(name);
|
||||
assert (x != null);
|
||||
}
|
||||
|
||||
@ -116,22 +116,22 @@ public class AbstractCharsetProvider
|
||||
protected void init() { }
|
||||
|
||||
private String canonicalize(String charsetName) {
|
||||
String acn = (String)aliasMap.get(charsetName);
|
||||
String acn = aliasMap.get(charsetName);
|
||||
return (acn != null) ? acn : charsetName;
|
||||
}
|
||||
|
||||
private Charset lookup(String csn) {
|
||||
|
||||
// Check cache first
|
||||
SoftReference sr = (SoftReference)cache.get(csn);
|
||||
SoftReference<Charset> sr = cache.get(csn);
|
||||
if (sr != null) {
|
||||
Charset cs = (Charset)sr.get();
|
||||
Charset cs = sr.get();
|
||||
if (cs != null)
|
||||
return cs;
|
||||
}
|
||||
|
||||
// Do we even support this charset?
|
||||
String cln = (String)classMap.get(csn);
|
||||
String cln = classMap.get(csn);
|
||||
|
||||
if (cln == null)
|
||||
return null;
|
||||
@ -139,12 +139,12 @@ public class AbstractCharsetProvider
|
||||
// Instantiate the charset and cache it
|
||||
try {
|
||||
|
||||
Class c = Class.forName(packagePrefix + "." + cln,
|
||||
true,
|
||||
this.getClass().getClassLoader());
|
||||
Class<?> c = Class.forName(packagePrefix + "." + cln,
|
||||
true,
|
||||
this.getClass().getClassLoader());
|
||||
|
||||
Charset cs = (Charset)c.newInstance();
|
||||
cache.put(csn, new SoftReference(cs));
|
||||
cache.put(csn, new SoftReference<Charset>(cs));
|
||||
return cs;
|
||||
} catch (ClassNotFoundException x) {
|
||||
return null;
|
||||
@ -164,21 +164,21 @@ public class AbstractCharsetProvider
|
||||
|
||||
public final Iterator<Charset> charsets() {
|
||||
|
||||
final ArrayList ks;
|
||||
final ArrayList<String> ks;
|
||||
synchronized (this) {
|
||||
init();
|
||||
ks = new ArrayList(classMap.keySet());
|
||||
ks = new ArrayList<>(classMap.keySet());
|
||||
}
|
||||
|
||||
return new Iterator<Charset>() {
|
||||
Iterator i = ks.iterator();
|
||||
Iterator<String> i = ks.iterator();
|
||||
|
||||
public boolean hasNext() {
|
||||
return i.hasNext();
|
||||
}
|
||||
|
||||
public Charset next() {
|
||||
String csn = (String)i.next();
|
||||
String csn = i.next();
|
||||
return lookup(csn);
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ public class AbstractCharsetProvider
|
||||
public final String[] aliases(String charsetName) {
|
||||
synchronized (this) {
|
||||
init();
|
||||
return (String[])aliasNameMap.get(charsetName);
|
||||
return aliasNameMap.get(charsetName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user