提交 388f5838 编写于 作者: S smarks

7116890: additional warnings fixes for java.io

Reviewed-by: alanb, smarks
Contributed-by: NSebastian Sickelmann <sebastian.sickelmann@gmx.de>
上级 a8848efe
...@@ -35,7 +35,7 @@ import java.util.Set; ...@@ -35,7 +35,7 @@ import java.util.Set;
class ExpiringCache { class ExpiringCache {
private long millisUntilExpiration; private long millisUntilExpiration;
private Map map; private Map<String,Entry> map;
// Clear out old entries every few queries // Clear out old entries every few queries
private int queryCount; private int queryCount;
private int queryOverflow = 300; private int queryOverflow = 300;
...@@ -61,10 +61,11 @@ class ExpiringCache { ...@@ -61,10 +61,11 @@ class ExpiringCache {
this(30000); this(30000);
} }
@SuppressWarnings("serial")
ExpiringCache(long millisUntilExpiration) { ExpiringCache(long millisUntilExpiration) {
this.millisUntilExpiration = millisUntilExpiration; this.millisUntilExpiration = millisUntilExpiration;
map = new LinkedHashMap() { map = new LinkedHashMap<String,Entry>() {
protected boolean removeEldestEntry(Map.Entry eldest) { protected boolean removeEldestEntry(Map.Entry<String,Entry> eldest) {
return size() > MAX_ENTRIES; return size() > MAX_ENTRIES;
} }
}; };
...@@ -99,7 +100,7 @@ class ExpiringCache { ...@@ -99,7 +100,7 @@ class ExpiringCache {
} }
private Entry entryFor(String key) { private Entry entryFor(String key) {
Entry entry = (Entry) map.get(key); Entry entry = map.get(key);
if (entry != null) { if (entry != null) {
long delta = System.currentTimeMillis() - entry.timestamp(); long delta = System.currentTimeMillis() - entry.timestamp();
if (delta < 0 || delta >= millisUntilExpiration) { if (delta < 0 || delta >= millisUntilExpiration) {
...@@ -111,12 +112,11 @@ class ExpiringCache { ...@@ -111,12 +112,11 @@ class ExpiringCache {
} }
private void cleanup() { private void cleanup() {
Set keySet = map.keySet(); Set<String> keySet = map.keySet();
// Avoid ConcurrentModificationExceptions // Avoid ConcurrentModificationExceptions
String[] keys = new String[keySet.size()]; String[] keys = new String[keySet.size()];
int i = 0; int i = 0;
for (Iterator iter = keySet.iterator(); iter.hasNext(); ) { for (String key: keySet) {
String key = (String) iter.next();
keys[i++] = key; keys[i++] = key;
} }
for (int j = 0; j < keys.length; j++) { for (int j = 0; j < keys.length; j++) {
......
...@@ -87,6 +87,7 @@ class LineNumberInputStream extends FilterInputStream { ...@@ -87,6 +87,7 @@ class LineNumberInputStream extends FilterInputStream {
* @see java.io.FilterInputStream#in * @see java.io.FilterInputStream#in
* @see java.io.LineNumberInputStream#getLineNumber() * @see java.io.LineNumberInputStream#getLineNumber()
*/ */
@SuppressWarnings("fallthrough")
public int read() throws IOException { public int read() throws IOException {
int c = pushBack; int c = pushBack;
......
...@@ -120,6 +120,7 @@ public class LineNumberReader extends BufferedReader { ...@@ -120,6 +120,7 @@ public class LineNumberReader extends BufferedReader {
* @throws IOException * @throws IOException
* If an I/O error occurs * If an I/O error occurs
*/ */
@SuppressWarnings("fallthrough")
public int read() throws IOException { public int read() throws IOException {
synchronized (lock) { synchronized (lock) {
int c = super.read(); int c = super.read();
...@@ -159,6 +160,7 @@ public class LineNumberReader extends BufferedReader { ...@@ -159,6 +160,7 @@ public class LineNumberReader extends BufferedReader {
* @throws IOException * @throws IOException
* If an I/O error occurs * If an I/O error occurs
*/ */
@SuppressWarnings("fallthrough")
public int read(char cbuf[], int off, int len) throws IOException { public int read(char cbuf[], int off, int len) throws IOException {
synchronized (lock) { synchronized (lock) {
int n = super.read(cbuf, off, len); int n = super.read(cbuf, off, len);
......
...@@ -1075,7 +1075,7 @@ public class ObjectOutputStream ...@@ -1075,7 +1075,7 @@ public class ObjectOutputStream
} catch (NoSuchMethodException ex) { } catch (NoSuchMethodException ex) {
} }
try { try {
cl.getDeclaredMethod("putFields", (Class[]) null); cl.getDeclaredMethod("putFields", (Class<?>[]) null);
return Boolean.FALSE; return Boolean.FALSE;
} catch (NoSuchMethodException ex) { } catch (NoSuchMethodException ex) {
} }
......
...@@ -1049,6 +1049,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable { ...@@ -1049,6 +1049,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
* @param s a string of bytes to be written. * @param s a string of bytes to be written.
* @exception IOException if an I/O error occurs. * @exception IOException if an I/O error occurs.
*/ */
@SuppressWarnings("deprecation")
public final void writeBytes(String s) throws IOException { public final void writeBytes(String s) throws IOException {
int len = s.length(); int len = s.length();
byte[] b = new byte[len]; byte[] b = new byte[len];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册