提交 8632cf43 编写于 作者: J jjg

7068616: NIO libraries do not build with javac -Xlint:all,-deprecation -Werror

Reviewed-by: alanb, chegar
Contributed-by: alexandre.boulgakov@oracle.com
上级 5b83d20b
# #
# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
# #
BUILDDIR = ../../.. BUILDDIR = ../../..
SUBDIRS_MAKEFLAGS += JAVAC_MAX_WARNINGS=true
SUBDIRS_MAKEFLAGS += JAVAC_WARNINGS_FATAL=true
include $(BUILDDIR)/common/Defs.gmk include $(BUILDDIR)/common/Defs.gmk
SUBDIRS = sctp SUBDIRS = sctp
......
...@@ -31,7 +31,6 @@ BUILDDIR = ../../../.. ...@@ -31,7 +31,6 @@ BUILDDIR = ../../../..
PACKAGE = com.sun.nio.sctp PACKAGE = com.sun.nio.sctp
LIBRARY = sctp LIBRARY = sctp
PRODUCT = sun PRODUCT = sun
#OTHER_JAVACFLAGS += -Xmaxwarns 1000 -Xlint
include $(BUILDDIR)/common/Defs.gmk include $(BUILDDIR)/common/Defs.gmk
# #
......
...@@ -31,7 +31,8 @@ BUILDDIR = ../.. ...@@ -31,7 +31,8 @@ BUILDDIR = ../..
PACKAGE = java.nio PACKAGE = java.nio
LIBRARY = nio LIBRARY = nio
PRODUCT = java PRODUCT = java
OTHER_JAVACFLAGS += -Xmaxwarns 1000 -Xlint:serial -Werror JAVAC_MAX_WARNINGS = true
JAVAC_WARNINGS_FATAL = true
include $(BUILDDIR)/common/Defs.gmk include $(BUILDDIR)/common/Defs.gmk
NIO_SRC = $(SHARE_SRC)/classes/java/nio NIO_SRC = $(SHARE_SRC)/classes/java/nio
......
# #
# Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -31,7 +31,9 @@ BUILDDIR = ../.. ...@@ -31,7 +31,9 @@ BUILDDIR = ../..
PACKAGE = sun.nio PACKAGE = sun.nio
PRODUCT = sun PRODUCT = sun
OTHER_JAVACFLAGS += -Xlint:serial,-deprecation -Werror JAVAC_MAX_WARNINGS = false
JAVAC_LINT_OPTIONS = -Xlint:all,-deprecation
JAVAC_WARNINGS_FATAL = true
include $(BUILDDIR)/common/Defs.gmk include $(BUILDDIR)/common/Defs.gmk
# #
......
# #
# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
BUILDDIR = ../.. BUILDDIR = ../..
PACKAGE = sun.nio PACKAGE = sun.nio
PRODUCT = sun PRODUCT = sun
SUBDIRS_MAKEFLAGS += JAVAC_MAX_WARNINGS=true
SUBDIRS_MAKEFLAGS += JAVAC_WARNINGS_FATAL=true
include $(BUILDDIR)/common/Defs.gmk include $(BUILDDIR)/common/Defs.gmk
SUBDIRS = cs SUBDIRS = cs
......
...@@ -36,7 +36,9 @@ PRODUCT = sun ...@@ -36,7 +36,9 @@ PRODUCT = sun
# This re-directs all the class files to a separate location # This re-directs all the class files to a separate location
CLASSDESTDIR = $(TEMPDIR)/classes CLASSDESTDIR = $(TEMPDIR)/classes
OTHER_JAVACFLAGS += -Xlint:serial,-deprecation -Werror JAVAC_MAX_WARNINGS = false
JAVAC_LINT_OPTIONS = -Xlint:all,-deprecation
JAVAC_WARNINGS_FATAL = true
include $(BUILDDIR)/common/Defs.gmk include $(BUILDDIR)/common/Defs.gmk
# #
......
/* /*
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1080,7 +1080,11 @@ public abstract class $Type$Buffer ...@@ -1080,7 +1080,11 @@ public abstract class $Type$Buffer
int h = 1; int h = 1;
int p = position(); int p = position();
for (int i = limit() - 1; i >= p; i--) for (int i = limit() - 1; i >= p; i--)
#if[int]
h = 31 * h + get(i);
#else[int]
h = 31 * h + (int)get(i); h = 31 * h + (int)get(i);
#end[int]
return h; return h;
} }
......
...@@ -248,6 +248,7 @@ public abstract class AsynchronousFileChannel ...@@ -248,6 +248,7 @@ public abstract class AsynchronousFileChannel
return provider.newAsynchronousFileChannel(file, options, executor, attrs); return provider.newAsynchronousFileChannel(file, options, executor, attrs);
} }
@SuppressWarnings({ "unchecked", "rawtypes" }) // generic array construction
private static final FileAttribute<?>[] NO_ATTRIBUTES = new FileAttribute[0]; private static final FileAttribute<?>[] NO_ATTRIBUTES = new FileAttribute[0];
/** /**
......
...@@ -287,6 +287,7 @@ public abstract class FileChannel ...@@ -287,6 +287,7 @@ public abstract class FileChannel
return provider.newFileChannel(path, options, attrs); return provider.newFileChannel(path, options, attrs);
} }
@SuppressWarnings({ "unchecked", "rawtypes" }) // generic array construction
private static final FileAttribute<?>[] NO_ATTRIBUTES = new FileAttribute[0]; private static final FileAttribute<?>[] NO_ATTRIBUTES = new FileAttribute[0];
/** /**
......
/* /*
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -29,7 +29,6 @@ import java.nio.ByteBuffer; ...@@ -29,7 +29,6 @@ import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.spi.CharsetProvider; import java.nio.charset.spi.CharsetProvider;
import java.security.AccessController; import java.security.AccessController;
import java.security.AccessControlException;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
...@@ -339,15 +338,15 @@ public abstract class Charset ...@@ -339,15 +338,15 @@ public abstract class Charset
// those whose lookup or instantiation causes a security exception to be // those whose lookup or instantiation causes a security exception to be
// thrown. Should be invoked with full privileges. // thrown. Should be invoked with full privileges.
// //
private static Iterator providers() { private static Iterator<CharsetProvider> providers() {
return new Iterator() { return new Iterator<CharsetProvider>() {
ClassLoader cl = ClassLoader.getSystemClassLoader(); ClassLoader cl = ClassLoader.getSystemClassLoader();
ServiceLoader<CharsetProvider> sl = ServiceLoader<CharsetProvider> sl =
ServiceLoader.load(CharsetProvider.class, cl); ServiceLoader.load(CharsetProvider.class, cl);
Iterator<CharsetProvider> i = sl.iterator(); Iterator<CharsetProvider> i = sl.iterator();
Object next = null; CharsetProvider next = null;
private boolean getNext() { private boolean getNext() {
while (next == null) { while (next == null) {
...@@ -370,10 +369,10 @@ public abstract class Charset ...@@ -370,10 +369,10 @@ public abstract class Charset
return getNext(); return getNext();
} }
public Object next() { public CharsetProvider next() {
if (!getNext()) if (!getNext())
throw new NoSuchElementException(); throw new NoSuchElementException();
Object n = next; CharsetProvider n = next;
next = null; next = null;
return n; return n;
} }
...@@ -386,7 +385,8 @@ public abstract class Charset ...@@ -386,7 +385,8 @@ public abstract class Charset
} }
// Thread-local gate to prevent recursive provider lookups // Thread-local gate to prevent recursive provider lookups
private static ThreadLocal<ThreadLocal> gate = new ThreadLocal<ThreadLocal>(); private static ThreadLocal<ThreadLocal<?>> gate =
new ThreadLocal<ThreadLocal<?>>();
private static Charset lookupViaProviders(final String charsetName) { private static Charset lookupViaProviders(final String charsetName) {
...@@ -410,8 +410,9 @@ public abstract class Charset ...@@ -410,8 +410,9 @@ public abstract class Charset
return AccessController.doPrivileged( return AccessController.doPrivileged(
new PrivilegedAction<Charset>() { new PrivilegedAction<Charset>() {
public Charset run() { public Charset run() {
for (Iterator i = providers(); i.hasNext();) { for (Iterator<CharsetProvider> i = providers();
CharsetProvider cp = (CharsetProvider)i.next(); i.hasNext();) {
CharsetProvider cp = i.next();
Charset cs = cp.charsetForName(charsetName); Charset cs = cp.charsetForName(charsetName);
if (cs != null) if (cs != null)
return cs; return cs;
...@@ -588,8 +589,8 @@ public abstract class Charset ...@@ -588,8 +589,8 @@ public abstract class Charset
new TreeMap<String,Charset>( new TreeMap<String,Charset>(
ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER); ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
put(standardProvider.charsets(), m); put(standardProvider.charsets(), m);
for (Iterator i = providers(); i.hasNext();) { for (Iterator<CharsetProvider> i = providers(); i.hasNext();) {
CharsetProvider cp = (CharsetProvider)i.next(); CharsetProvider cp = i.next();
put(cp.charsets(), m); put(cp.charsets(), m);
} }
return Collections.unmodifiableSortedMap(m); return Collections.unmodifiableSortedMap(m);
......
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -390,8 +390,10 @@ public class DatagramSocketAdaptor ...@@ -390,8 +390,10 @@ public class DatagramSocketAdaptor
protected void receive(DatagramPacket p) throws IOException {} protected void receive(DatagramPacket p) throws IOException {}
@Deprecated
protected void setTTL(byte ttl) throws IOException {} protected void setTTL(byte ttl) throws IOException {}
@Deprecated
protected byte getTTL() throws IOException { return 0; } protected byte getTTL() throws IOException { return 0; }
protected void setTimeToLive(int ttl) throws IOException {} protected void setTimeToLive(int ttl) throws IOException {}
......
/* /*
* Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -50,29 +50,25 @@ class Reflect { // package-private ...@@ -50,29 +50,25 @@ class Reflect { // package-private
}}); }});
} }
static Constructor lookupConstructor(String className, static Constructor<?> lookupConstructor(String className,
Class[] paramTypes) Class<?>[] paramTypes)
{ {
try { try {
Class<?> cl = Class.forName(className); Class<?> cl = Class.forName(className);
Constructor<?> c = cl.getDeclaredConstructor(paramTypes); Constructor<?> c = cl.getDeclaredConstructor(paramTypes);
setAccessible(c); setAccessible(c);
return c; return c;
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException | NoSuchMethodException x) {
throw new ReflectionError(x);
} catch (NoSuchMethodException x) {
throw new ReflectionError(x); throw new ReflectionError(x);
} }
} }
static Object invoke(Constructor c, Object[] args) { static Object invoke(Constructor<?> c, Object[] args) {
try { try {
return c.newInstance(args); return c.newInstance(args);
} catch (InstantiationException x) { } catch (InstantiationException |
throw new ReflectionError(x); IllegalAccessException |
} catch (IllegalAccessException x) { InvocationTargetException x) {
throw new ReflectionError(x);
} catch (InvocationTargetException x) {
throw new ReflectionError(x); throw new ReflectionError(x);
} }
} }
...@@ -86,9 +82,7 @@ class Reflect { // package-private ...@@ -86,9 +82,7 @@ class Reflect { // package-private
Method m = cl.getDeclaredMethod(methodName, paramTypes); Method m = cl.getDeclaredMethod(methodName, paramTypes);
setAccessible(m); setAccessible(m);
return m; return m;
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException | NoSuchMethodException x) {
throw new ReflectionError(x);
} catch (NoSuchMethodException x) {
throw new ReflectionError(x); throw new ReflectionError(x);
} }
} }
...@@ -96,9 +90,7 @@ class Reflect { // package-private ...@@ -96,9 +90,7 @@ class Reflect { // package-private
static Object invoke(Method m, Object ob, Object[] args) { static Object invoke(Method m, Object ob, Object[] args) {
try { try {
return m.invoke(ob, args); return m.invoke(ob, args);
} catch (IllegalAccessException x) { } catch (IllegalAccessException | InvocationTargetException x) {
throw new ReflectionError(x);
} catch (InvocationTargetException x) {
throw new ReflectionError(x); throw new ReflectionError(x);
} }
} }
...@@ -119,13 +111,11 @@ class Reflect { // package-private ...@@ -119,13 +111,11 @@ class Reflect { // package-private
static Field lookupField(String className, String fieldName) { static Field lookupField(String className, String fieldName) {
try { try {
Class cl = Class.forName(className); Class<?> cl = Class.forName(className);
Field f = cl.getDeclaredField(fieldName); Field f = cl.getDeclaredField(fieldName);
setAccessible(f); setAccessible(f);
return f; return f;
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException | NoSuchFieldException x) {
throw new ReflectionError(x);
} catch (NoSuchFieldException x) {
throw new ReflectionError(x); throw new ReflectionError(x);
} }
} }
......
/* /*
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,7 +30,6 @@ import java.nio.channels.*; ...@@ -30,7 +30,6 @@ import java.nio.channels.*;
import java.nio.channels.spi.*; import java.nio.channels.spi.*;
import java.net.SocketException; import java.net.SocketException;
import java.util.*; import java.util.*;
import sun.misc.*;
/** /**
...@@ -140,19 +139,16 @@ abstract class SelectorImpl ...@@ -140,19 +139,16 @@ abstract class SelectorImpl
void processDeregisterQueue() throws IOException { void processDeregisterQueue() throws IOException {
// Precondition: Synchronized on this, keys, and selectedKeys // Precondition: Synchronized on this, keys, and selectedKeys
Set cks = cancelledKeys(); Set<SelectionKey> cks = cancelledKeys();
synchronized (cks) { synchronized (cks) {
if (!cks.isEmpty()) { if (!cks.isEmpty()) {
Iterator i = cks.iterator(); Iterator<SelectionKey> i = cks.iterator();
while (i.hasNext()) { while (i.hasNext()) {
SelectionKeyImpl ski = (SelectionKeyImpl)i.next(); SelectionKeyImpl ski = (SelectionKeyImpl)i.next();
try { try {
implDereg(ski); implDereg(ski);
} catch (SocketException se) { } catch (SocketException se) {
IOException ioe = new IOException( throw new IOException("Error deregistering key", se);
"Error deregistering key");
ioe.initCause(se);
throw ioe;
} finally { } finally {
i.remove(); i.remove();
} }
......
/* /*
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -355,27 +355,24 @@ class Util { ...@@ -355,27 +355,24 @@ class Util {
return pageSize; return pageSize;
} }
private static volatile Constructor directByteBufferConstructor = null; private static volatile Constructor<?> directByteBufferConstructor = null;
private static void initDBBConstructor() { private static void initDBBConstructor() {
AccessController.doPrivileged(new PrivilegedAction<Void>() { AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() { public Void run() {
try { try {
Class<?> cl = Class.forName("java.nio.DirectByteBuffer"); Class<?> cl = Class.forName("java.nio.DirectByteBuffer");
Constructor ctor = cl.getDeclaredConstructor( Constructor<?> ctor = cl.getDeclaredConstructor(
new Class[] { int.class, new Class[] { int.class,
long.class, long.class,
FileDescriptor.class, FileDescriptor.class,
Runnable.class }); Runnable.class });
ctor.setAccessible(true); ctor.setAccessible(true);
directByteBufferConstructor = ctor; directByteBufferConstructor = ctor;
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException |
throw new InternalError(); NoSuchMethodException |
} catch (NoSuchMethodException x) { IllegalArgumentException |
throw new InternalError(); ClassCastException x) {
} catch (IllegalArgumentException x) {
throw new InternalError();
} catch (ClassCastException x) {
throw new InternalError(); throw new InternalError();
} }
return null; return null;
...@@ -395,37 +392,32 @@ class Util { ...@@ -395,37 +392,32 @@ class Util {
new Long(addr), new Long(addr),
fd, fd,
unmapper }); unmapper });
} catch (InstantiationException e) { } catch (InstantiationException |
throw new InternalError(); IllegalAccessException |
} catch (IllegalAccessException e) { InvocationTargetException e) {
throw new InternalError();
} catch (InvocationTargetException e) {
throw new InternalError(); throw new InternalError();
} }
return dbb; return dbb;
} }
private static volatile Constructor directByteBufferRConstructor = null; private static volatile Constructor<?> directByteBufferRConstructor = null;
private static void initDBBRConstructor() { private static void initDBBRConstructor() {
AccessController.doPrivileged(new PrivilegedAction<Void>() { AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() { public Void run() {
try { try {
Class<?> cl = Class.forName("java.nio.DirectByteBufferR"); Class<?> cl = Class.forName("java.nio.DirectByteBufferR");
Constructor ctor = cl.getDeclaredConstructor( Constructor<?> ctor = cl.getDeclaredConstructor(
new Class[] { int.class, new Class[] { int.class,
long.class, long.class,
FileDescriptor.class, FileDescriptor.class,
Runnable.class }); Runnable.class });
ctor.setAccessible(true); ctor.setAccessible(true);
directByteBufferRConstructor = ctor; directByteBufferRConstructor = ctor;
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException |
throw new InternalError(); NoSuchMethodException |
} catch (NoSuchMethodException x) { IllegalArgumentException |
throw new InternalError(); ClassCastException x) {
} catch (IllegalArgumentException x) {
throw new InternalError();
} catch (ClassCastException x) {
throw new InternalError(); throw new InternalError();
} }
return null; return null;
...@@ -445,11 +437,9 @@ class Util { ...@@ -445,11 +437,9 @@ class Util {
new Long(addr), new Long(addr),
fd, fd,
unmapper }); unmapper });
} catch (InstantiationException e) { } catch (InstantiationException |
throw new InternalError(); IllegalAccessException |
} catch (IllegalAccessException e) { InvocationTargetException e) {
throw new InternalError();
} catch (InvocationTargetException e) {
throw new InternalError(); throw new InternalError();
} }
return dbb; return dbb;
......
/* /*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
package sun.nio.cs; package sun.nio.cs;
import java.lang.ref.SoftReference;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.spi.CharsetProvider; import java.nio.charset.spi.CharsetProvider;
import java.util.Iterator; import java.util.Iterator;
...@@ -116,17 +115,15 @@ public class FastCharsetProvider ...@@ -116,17 +115,15 @@ public class FastCharsetProvider
// 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());
cs = (Charset)c.newInstance(); cs = (Charset)c.newInstance();
cache.put(csn, cs); cache.put(csn, cs);
return cs; return cs;
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException |
return null; IllegalAccessException |
} catch (IllegalAccessException x) { InstantiationException x) {
return null;
} catch (InstantiationException x) {
return null; return null;
} }
} }
......
/* /*
* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -112,6 +112,7 @@ public class StreamDecoder extends Reader ...@@ -112,6 +112,7 @@ public class StreamDecoder extends Reader
return read0(); return read0();
} }
@SuppressWarnings("fallthrough")
private int read0() throws IOException { private int read0() throws IOException {
synchronized (lock) { synchronized (lock) {
......
/* /*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
package sun.nio.cs; package sun.nio.cs;
import java.nio.*;
import java.nio.charset.*; import java.nio.charset.*;
...@@ -41,7 +40,7 @@ public class ThreadLocalCoders { ...@@ -41,7 +40,7 @@ public class ThreadLocalCoders {
private static abstract class Cache { private static abstract class Cache {
// Thread-local reference to array of cached objects, in LRU order // Thread-local reference to array of cached objects, in LRU order
private ThreadLocal cache = new ThreadLocal(); private ThreadLocal<Object[]> cache = new ThreadLocal<>();
private final int size; private final int size;
Cache(int size) { Cache(int size) {
...@@ -60,7 +59,7 @@ public class ThreadLocalCoders { ...@@ -60,7 +59,7 @@ public class ThreadLocalCoders {
abstract boolean hasName(Object ob, Object name); abstract boolean hasName(Object ob, Object name);
Object forName(Object name) { Object forName(Object name) {
Object[] oa = (Object[])cache.get(); Object[] oa = cache.get();
if (oa == null) { if (oa == null) {
oa = new Object[size]; oa = new Object[size];
cache.set(oa); cache.set(oa);
......
...@@ -62,6 +62,7 @@ class Util { ...@@ -62,6 +62,7 @@ class Util {
/** /**
* Returns a Set containing the given elements. * Returns a Set containing the given elements.
*/ */
@SafeVarargs
static <E> Set<E> newSet(E... elements) { static <E> Set<E> newSet(E... elements) {
HashSet<E> set = new HashSet<>(); HashSet<E> set = new HashSet<>();
for (E e: elements) { for (E e: elements) {
...@@ -74,6 +75,7 @@ class Util { ...@@ -74,6 +75,7 @@ class Util {
* Returns a Set containing all the elements of the given Set plus * Returns a Set containing all the elements of the given Set plus
* the given elements. * the given elements.
*/ */
@SafeVarargs
static <E> Set<E> newSet(Set<E> other, E... elements) { static <E> Set<E> newSet(Set<E> other, E... elements) {
HashSet<E> set = new HashSet<>(other); HashSet<E> set = new HashSet<>(other);
for (E e: elements) { for (E e: elements) {
......
/* /*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -53,8 +53,6 @@ import com.sun.nio.sctp.MessageInfo; ...@@ -53,8 +53,6 @@ import com.sun.nio.sctp.MessageInfo;
import com.sun.nio.sctp.NotificationHandler; import com.sun.nio.sctp.NotificationHandler;
import com.sun.nio.sctp.SctpChannel; import com.sun.nio.sctp.SctpChannel;
import com.sun.nio.sctp.SctpSocketOption; import com.sun.nio.sctp.SctpSocketOption;
import sun.nio.ch.PollArrayWrapper;
import sun.nio.ch.SelChImpl;
import static com.sun.nio.sctp.SctpStandardSocketOptions.*; import static com.sun.nio.sctp.SctpStandardSocketOptions.*;
import static sun.nio.ch.SctpResultContainer.SEND_FAILED; import static sun.nio.ch.SctpResultContainer.SEND_FAILED;
import static sun.nio.ch.SctpResultContainer.ASSOCIATION_CHANGED; import static sun.nio.ch.SctpResultContainer.ASSOCIATION_CHANGED;
...@@ -118,7 +116,7 @@ public class SctpChannelImpl extends SctpChannel ...@@ -118,7 +116,7 @@ public class SctpChannelImpl extends SctpChannel
private Association association; private Association association;
private Set<SocketAddress> remoteAddresses = Collections.EMPTY_SET; private Set<SocketAddress> remoteAddresses = Collections.emptySet();
/* -- End of fields protected by stateLock -- */ /* -- End of fields protected by stateLock -- */
...@@ -853,7 +851,7 @@ public class SctpChannelImpl extends SctpChannel ...@@ -853,7 +851,7 @@ public class SctpChannelImpl extends SctpChannel
return n; return n;
} }
private InternalNotificationHandler<?> internalNotificationHandler = private InternalNotificationHandler internalNotificationHandler =
new InternalNotificationHandler(); new InternalNotificationHandler();
private void handleNotificationInternal(SctpResultContainer resultContainer) private void handleNotificationInternal(SctpResultContainer resultContainer)
...@@ -862,12 +860,12 @@ public class SctpChannelImpl extends SctpChannel ...@@ -862,12 +860,12 @@ public class SctpChannelImpl extends SctpChannel
internalNotificationHandler, null); internalNotificationHandler, null);
} }
private class InternalNotificationHandler<T> private class InternalNotificationHandler
extends AbstractNotificationHandler<T> extends AbstractNotificationHandler<Object>
{ {
@Override @Override
public HandlerResult handleNotification( public HandlerResult handleNotification(
AssociationChangeNotification not, T unused) { AssociationChangeNotification not, Object unused) {
if (not.event().equals( if (not.event().equals(
AssociationChangeNotification.AssocChangeEvent.COMM_UP) && AssociationChangeNotification.AssocChangeEvent.COMM_UP) &&
association == null) { association == null) {
...@@ -893,8 +891,8 @@ public class SctpChannelImpl extends SctpChannel ...@@ -893,8 +891,8 @@ public class SctpChannelImpl extends SctpChannel
} }
/* AbstractNotificationHandler */ /* AbstractNotificationHandler */
AbstractNotificationHandler absHandler = AbstractNotificationHandler<T> absHandler =
(AbstractNotificationHandler)handler; (AbstractNotificationHandler<T>)handler;
switch(resultContainer.type()) { switch(resultContainer.type()) {
case ASSOCIATION_CHANGED : case ASSOCIATION_CHANGED :
return absHandler.handleNotification( return absHandler.handleNotification(
...@@ -1053,7 +1051,7 @@ public class SctpChannelImpl extends SctpChannel ...@@ -1053,7 +1051,7 @@ public class SctpChannelImpl extends SctpChannel
if (!isOpen()) if (!isOpen())
throw new ClosedChannelException(); throw new ClosedChannelException();
if (!isBound()) if (!isBound())
return Collections.EMPTY_SET; return Collections.emptySet();
return SctpNet.getLocalAddresses(fdVal); return SctpNet.getLocalAddresses(fdVal);
} }
...@@ -1066,7 +1064,7 @@ public class SctpChannelImpl extends SctpChannel ...@@ -1066,7 +1064,7 @@ public class SctpChannelImpl extends SctpChannel
if (!isOpen()) if (!isOpen())
throw new ClosedChannelException(); throw new ClosedChannelException();
if (!isConnected() || isShutdown) if (!isConnected() || isShutdown)
return Collections.EMPTY_SET; return Collections.emptySet();
try { try {
return SctpNet.getRemoteAddresses(fdVal, 0/*unused*/); return SctpNet.getRemoteAddresses(fdVal, 0/*unused*/);
......
/* /*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -586,12 +586,12 @@ public class SctpMultiChannelImpl extends SctpMultiChannel ...@@ -586,12 +586,12 @@ public class SctpMultiChannelImpl extends SctpMultiChannel
internalNotificationHandler, null); internalNotificationHandler, null);
} }
private class InternalNotificationHandler<T> private class InternalNotificationHandler
extends AbstractNotificationHandler<T> extends AbstractNotificationHandler<Object>
{ {
@Override @Override
public HandlerResult handleNotification( public HandlerResult handleNotification(
AssociationChangeNotification not, T unused) { AssociationChangeNotification not, Object unused) {
SctpAssocChange sac = (SctpAssocChange) not; SctpAssocChange sac = (SctpAssocChange) not;
/* Update map to reflect change in association */ /* Update map to reflect change in association */
...@@ -622,8 +622,8 @@ public class SctpMultiChannelImpl extends SctpMultiChannel ...@@ -622,8 +622,8 @@ public class SctpMultiChannelImpl extends SctpMultiChannel
if (!(handler instanceof AbstractNotificationHandler)) { if (!(handler instanceof AbstractNotificationHandler)) {
result = handler.handleNotification(notification, attachment); result = handler.handleNotification(notification, attachment);
} else { /* AbstractNotificationHandler */ } else { /* AbstractNotificationHandler */
AbstractNotificationHandler absHandler = AbstractNotificationHandler<T> absHandler =
(AbstractNotificationHandler)handler; (AbstractNotificationHandler<T>)handler;
switch(resultContainer.type()) { switch(resultContainer.type()) {
case ASSOCIATION_CHANGED : case ASSOCIATION_CHANGED :
result = absHandler.handleNotification( result = absHandler.handleNotification(
...@@ -912,7 +912,7 @@ public class SctpMultiChannelImpl extends SctpMultiChannel ...@@ -912,7 +912,7 @@ public class SctpMultiChannelImpl extends SctpMultiChannel
if (!isOpen()) if (!isOpen())
throw new ClosedChannelException(); throw new ClosedChannelException();
if (!isBound()) if (!isBound())
return Collections.EMPTY_SET; return Collections.emptySet();
return SctpNet.getLocalAddresses(fdVal); return SctpNet.getLocalAddresses(fdVal);
} }
...@@ -931,7 +931,7 @@ public class SctpMultiChannelImpl extends SctpMultiChannel ...@@ -931,7 +931,7 @@ public class SctpMultiChannelImpl extends SctpMultiChannel
} catch (SocketException se) { } catch (SocketException se) {
/* a valid association should always have remote addresses */ /* a valid association should always have remote addresses */
Set<SocketAddress> addrs = associationMap.get(association); Set<SocketAddress> addrs = associationMap.get(association);
return addrs != null ? addrs : Collections.EMPTY_SET; return addrs != null ? addrs : Collections.<SocketAddress>emptySet();
} }
} }
} }
......
/* /*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -118,18 +118,14 @@ public class SctpNet { ...@@ -118,18 +118,14 @@ public class SctpNet {
return set; return set;
} }
static void setSocketOption(int fd, static <T> void setSocketOption(int fd,
SctpSocketOption name, SctpSocketOption<T> name,
Object value, T value,
int assocId) int assocId)
throws IOException { throws IOException {
if (value == null) if (value == null)
throw new IllegalArgumentException("Invalid option value"); throw new IllegalArgumentException("Invalid option value");
Class<?> type = name.type();
if (!type.isInstance(value))
throw new IllegalArgumentException("Invalid option value");
if (name.equals(SCTP_INIT_MAXSTREAMS)) { if (name.equals(SCTP_INIT_MAXSTREAMS)) {
InitMaxStreams maxStreamValue = (InitMaxStreams)value; InitMaxStreams maxStreamValue = (InitMaxStreams)value;
SctpNet.setInitMsgOption0(fd, SctpNet.setInitMsgOption0(fd,
...@@ -169,7 +165,7 @@ public class SctpNet { ...@@ -169,7 +165,7 @@ public class SctpNet {
} }
} }
static Object getSocketOption(int fd, SctpSocketOption name, int assocId) static Object getSocketOption(int fd, SctpSocketOption<?> name, int assocId)
throws IOException { throws IOException {
if (name.equals(SCTP_SET_PEER_PRIMARY_ADDR)) { if (name.equals(SCTP_SET_PEER_PRIMARY_ADDR)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
...@@ -194,7 +190,7 @@ public class SctpNet { ...@@ -194,7 +190,7 @@ public class SctpNet {
} }
} }
static void setIntOption(int fd, SctpSocketOption name, Object value) static void setIntOption(int fd, SctpSocketOption<?> name, Object value)
throws IOException { throws IOException {
if (value == null) if (value == null)
throw new IllegalArgumentException("Invalid option value"); throw new IllegalArgumentException("Invalid option value");
...@@ -234,7 +230,7 @@ public class SctpNet { ...@@ -234,7 +230,7 @@ public class SctpNet {
setIntOption0(fd, ((SctpStdSocketOption)name).constValue(), arg); setIntOption0(fd, ((SctpStdSocketOption)name).constValue(), arg);
} }
static Object getIntOption(int fd, SctpSocketOption name) static Object getIntOption(int fd, SctpSocketOption<?> name)
throws IOException { throws IOException {
Class<?> type = name.type(); Class<?> type = name.type();
......
/* /*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -367,6 +367,7 @@ public class SctpServerChannelImpl extends SctpServerChannel ...@@ -367,6 +367,7 @@ public class SctpServerChannelImpl extends SctpServerChannel
} }
@Override @Override
@SuppressWarnings("unchecked")
public <T> T getOption(SctpSocketOption<T> name) throws IOException { public <T> T getOption(SctpSocketOption<T> name) throws IOException {
if (name == null) if (name == null)
throw new NullPointerException(); throw new NullPointerException();
...@@ -403,7 +404,7 @@ public class SctpServerChannelImpl extends SctpServerChannel ...@@ -403,7 +404,7 @@ public class SctpServerChannelImpl extends SctpServerChannel
if (!isOpen()) if (!isOpen())
throw new ClosedChannelException(); throw new ClosedChannelException();
if (!isBound()) if (!isBound())
return Collections.EMPTY_SET; return Collections.emptySet();
return SctpNet.getLocalAddresses(fdVal); return SctpNet.getLocalAddresses(fdVal);
} }
......
...@@ -60,6 +60,7 @@ class PendingIoCache { ...@@ -60,6 +60,7 @@ class PendingIoCache {
private boolean closePending; private boolean closePending;
// maps OVERLAPPED to PendingFuture // maps OVERLAPPED to PendingFuture
@SuppressWarnings("rawtypes")
private final Map<Long,PendingFuture> pendingIoMap = private final Map<Long,PendingFuture> pendingIoMap =
new HashMap<Long,PendingFuture>(); new HashMap<Long,PendingFuture>();
......
...@@ -314,7 +314,7 @@ public class WindowsAsynchronousFileChannelImpl ...@@ -314,7 +314,7 @@ public class WindowsAsynchronousFileChannelImpl
// create Future and task that will be invoked to acquire lock // create Future and task that will be invoked to acquire lock
PendingFuture<FileLock,A> result = PendingFuture<FileLock,A> result =
new PendingFuture<FileLock,A>(this, handler, attachment); new PendingFuture<FileLock,A>(this, handler, attachment);
LockTask lockTask = new LockTask<A>(position, fli, result); LockTask<A> lockTask = new LockTask<A>(position, fli, result);
result.setContext(lockTask); result.setContext(lockTask);
// initiate I/O // initiate I/O
...@@ -552,7 +552,7 @@ public class WindowsAsynchronousFileChannelImpl ...@@ -552,7 +552,7 @@ public class WindowsAsynchronousFileChannelImpl
// create Future and task that initiates read // create Future and task that initiates read
PendingFuture<Integer,A> result = PendingFuture<Integer,A> result =
new PendingFuture<Integer,A>(this, handler, attachment); new PendingFuture<Integer,A>(this, handler, attachment);
ReadTask readTask = new ReadTask<A>(dst, pos, rem, position, result); ReadTask<A> readTask = new ReadTask<A>(dst, pos, rem, position, result);
result.setContext(readTask); result.setContext(readTask);
// initiate I/O // initiate I/O
...@@ -726,7 +726,7 @@ public class WindowsAsynchronousFileChannelImpl ...@@ -726,7 +726,7 @@ public class WindowsAsynchronousFileChannelImpl
// create Future and task to initiate write // create Future and task to initiate write
PendingFuture<Integer,A> result = PendingFuture<Integer,A> result =
new PendingFuture<Integer,A>(this, handler, attachment); new PendingFuture<Integer,A>(this, handler, attachment);
WriteTask writeTask = new WriteTask<A>(src, pos, rem, position, result); WriteTask<A> writeTask = new WriteTask<A>(src, pos, rem, position, result);
result.setContext(writeTask); result.setContext(writeTask);
// initiate I/O // initiate I/O
......
...@@ -351,7 +351,7 @@ class WindowsAsynchronousSocketChannelImpl ...@@ -351,7 +351,7 @@ class WindowsAsynchronousSocketChannelImpl
// setup task // setup task
PendingFuture<Void,A> result = PendingFuture<Void,A> result =
new PendingFuture<Void,A>(this, handler, attachment); new PendingFuture<Void,A>(this, handler, attachment);
ConnectTask task = new ConnectTask<A>(isa, result); ConnectTask<A> task = new ConnectTask<A>(isa, result);
result.setContext(task); result.setContext(task);
// initiate I/O // initiate I/O
...@@ -615,7 +615,8 @@ class WindowsAsynchronousSocketChannelImpl ...@@ -615,7 +615,8 @@ class WindowsAsynchronousSocketChannelImpl
bufs = new ByteBuffer[1]; bufs = new ByteBuffer[1];
bufs[0] = dst; bufs[0] = dst;
} }
final ReadTask readTask = new ReadTask<V,A>(bufs, isScatteringRead, result); final ReadTask<V,A> readTask =
new ReadTask<V,A>(bufs, isScatteringRead, result);
result.setContext(readTask); result.setContext(readTask);
// schedule timeout // schedule timeout
...@@ -872,7 +873,8 @@ class WindowsAsynchronousSocketChannelImpl ...@@ -872,7 +873,8 @@ class WindowsAsynchronousSocketChannelImpl
bufs = new ByteBuffer[1]; bufs = new ByteBuffer[1];
bufs[0] = src; bufs[0] = src;
} }
final WriteTask writeTask = new WriteTask<V,A>(bufs, gatheringWrite, result); final WriteTask<V,A> writeTask =
new WriteTask<V,A>(bufs, gatheringWrite, result);
result.setContext(writeTask); result.setContext(writeTask);
// schedule timeout // schedule timeout
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册