提交 63c3702e 编写于 作者: A andrew

6921740: Eliminate warnings from sun.io converters and allow compiling with JAVAC_MAX_WARNINGS=true

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