8032779: Update code in java.lang to use newer language features
Reviewed-by: darcy, alanb
This commit is contained in:
parent
2489c7b220
commit
51efd87812
@ -1488,10 +1488,9 @@ public final class Class<T> implements java.io.Serializable,
|
||||
List<Class<?>> list = new ArrayList<>();
|
||||
Class<?> currentClass = Class.this;
|
||||
while (currentClass != null) {
|
||||
Class<?>[] members = currentClass.getDeclaredClasses();
|
||||
for (int i = 0; i < members.length; i++) {
|
||||
if (Modifier.isPublic(members[i].getModifiers())) {
|
||||
list.add(members[i]);
|
||||
for (Class<?> m : currentClass.getDeclaredClasses()) {
|
||||
if (Modifier.isPublic(m.getModifiers())) {
|
||||
list.add(m);
|
||||
}
|
||||
}
|
||||
currentClass = currentClass.getSuperclass();
|
||||
@ -2626,8 +2625,8 @@ public final class Class<T> implements java.io.Serializable,
|
||||
}
|
||||
|
||||
private static void addAll(Collection<Field> c, Field[] o) {
|
||||
for (int i = 0; i < o.length; i++) {
|
||||
c.add(o[i]);
|
||||
for (Field f : o) {
|
||||
c.add(f);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2713,8 +2712,8 @@ public final class Class<T> implements java.io.Serializable,
|
||||
}
|
||||
|
||||
void addAll(Method[] ma) {
|
||||
for (int i = 0; i < ma.length; i++) {
|
||||
add(ma[i]);
|
||||
for (Method m : ma) {
|
||||
add(m);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2819,9 +2818,8 @@ public final class Class<T> implements java.io.Serializable,
|
||||
// out concrete implementations inherited from superclasses at
|
||||
// the end.
|
||||
MethodArray inheritedMethods = new MethodArray();
|
||||
Class<?>[] interfaces = getInterfaces();
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
inheritedMethods.addAllNonStatic(interfaces[i].privateGetPublicMethods());
|
||||
for (Class<?> i : getInterfaces()) {
|
||||
inheritedMethods.addAllNonStatic(i.privateGetPublicMethods());
|
||||
}
|
||||
if (!isInterface()) {
|
||||
Class<?> c = getSuperclass();
|
||||
@ -2864,9 +2862,9 @@ public final class Class<T> implements java.io.Serializable,
|
||||
|
||||
private static Field searchFields(Field[] fields, String name) {
|
||||
String internedName = name.intern();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
if (fields[i].getName() == internedName) {
|
||||
return getReflectionFactory().copyField(fields[i]);
|
||||
for (Field field : fields) {
|
||||
if (field.getName() == internedName) {
|
||||
return getReflectionFactory().copyField(field);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -2887,8 +2885,7 @@ public final class Class<T> implements java.io.Serializable,
|
||||
}
|
||||
// Direct superinterfaces, recursively
|
||||
Class<?>[] interfaces = getInterfaces();
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
Class<?> c = interfaces[i];
|
||||
for (Class<?> c : interfaces) {
|
||||
if ((res = c.getField0(name)) != null) {
|
||||
return res;
|
||||
}
|
||||
@ -2911,8 +2908,7 @@ public final class Class<T> implements java.io.Serializable,
|
||||
{
|
||||
Method res = null;
|
||||
String internedName = name.intern();
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
Method m = methods[i];
|
||||
for (Method m : methods) {
|
||||
if (m.getName() == internedName
|
||||
&& arrayContentsEq(parameterTypes, m.getParameterTypes())
|
||||
&& (res == null
|
||||
|
@ -199,8 +199,7 @@ public abstract class ClassLoader {
|
||||
|
||||
// the set of parallel capable loader types
|
||||
private static final Set<Class<? extends ClassLoader>> loaderTypes =
|
||||
Collections.newSetFromMap(
|
||||
new WeakHashMap<Class<? extends ClassLoader>, Boolean>());
|
||||
Collections.newSetFromMap(new WeakHashMap<>());
|
||||
static {
|
||||
synchronized (loaderTypes) { loaderTypes.add(ClassLoader.class); }
|
||||
}
|
||||
@ -285,8 +284,7 @@ public abstract class ClassLoader {
|
||||
if (ParallelLoaders.isRegistered(this.getClass())) {
|
||||
parallelLockMap = new ConcurrentHashMap<>();
|
||||
package2certs = new ConcurrentHashMap<>();
|
||||
domains =
|
||||
Collections.synchronizedSet(new HashSet<ProtectionDomain>());
|
||||
domains = Collections.synchronizedSet(new HashSet<>());
|
||||
assertionLock = new Object();
|
||||
} else {
|
||||
// no finer-grained lock; lock on the classloader instance
|
||||
@ -916,10 +914,10 @@ public abstract class ClassLoader {
|
||||
// go through and make sure all the certs in one array
|
||||
// are in the other and vice-versa.
|
||||
boolean match;
|
||||
for (int i = 0; i < certs.length; i++) {
|
||||
for (Certificate cert : certs) {
|
||||
match = false;
|
||||
for (int j = 0; j < pcerts.length; j++) {
|
||||
if (certs[i].equals(pcerts[j])) {
|
||||
for (Certificate pcert : pcerts) {
|
||||
if (cert.equals(pcert)) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
@ -928,10 +926,10 @@ public abstract class ClassLoader {
|
||||
}
|
||||
|
||||
// now do the same for pcerts
|
||||
for (int i = 0; i < pcerts.length; i++) {
|
||||
for (Certificate pcert : pcerts) {
|
||||
match = false;
|
||||
for (int j = 0; j < certs.length; j++) {
|
||||
if (pcerts[i].equals(certs[j])) {
|
||||
for (Certificate cert : certs) {
|
||||
if (pcert.equals(cert)) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
@ -1648,10 +1646,10 @@ public abstract class ClassLoader {
|
||||
pkgs = Package.getSystemPackages();
|
||||
}
|
||||
if (pkgs != null) {
|
||||
for (int i = 0; i < pkgs.length; i++) {
|
||||
String pkgName = pkgs[i].getName();
|
||||
for (Package pkg : pkgs) {
|
||||
String pkgName = pkg.getName();
|
||||
if (map.get(pkgName) == null) {
|
||||
map.put(pkgName, pkgs[i]);
|
||||
map.put(pkgName, pkg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1830,8 +1828,8 @@ public abstract class ClassLoader {
|
||||
throw new UnsatisfiedLinkError("Can't load " + libfilename);
|
||||
}
|
||||
}
|
||||
for (int i = 0 ; i < sys_paths.length ; i++) {
|
||||
File libfile = new File(sys_paths[i], System.mapLibraryName(name));
|
||||
for (String sys_path : sys_paths) {
|
||||
File libfile = new File(sys_path, System.mapLibraryName(name));
|
||||
if (loadLibrary0(fromClass, libfile)) {
|
||||
return;
|
||||
}
|
||||
@ -1841,9 +1839,8 @@ public abstract class ClassLoader {
|
||||
}
|
||||
}
|
||||
if (loader != null) {
|
||||
for (int i = 0 ; i < usr_paths.length ; i++) {
|
||||
File libfile = new File(usr_paths[i],
|
||||
System.mapLibraryName(name));
|
||||
for (String usr_path : usr_paths) {
|
||||
File libfile = new File(usr_path, System.mapLibraryName(name));
|
||||
if (loadLibrary0(fromClass, libfile)) {
|
||||
return;
|
||||
}
|
||||
|
@ -91,15 +91,14 @@ final class ConditionalSpecialCasing {
|
||||
static Hashtable<Integer, HashSet<Entry>> entryTable = new Hashtable<>();
|
||||
static {
|
||||
// create hashtable from the entry
|
||||
for (int i = 0; i < entry.length; i ++) {
|
||||
Entry cur = entry[i];
|
||||
Integer cp = new Integer(cur.getCodePoint());
|
||||
for (Entry cur : entry) {
|
||||
Integer cp = cur.getCodePoint();
|
||||
HashSet<Entry> set = entryTable.get(cp);
|
||||
if (set == null) {
|
||||
set = new HashSet<Entry>();
|
||||
set = new HashSet<>();
|
||||
entryTable.put(cp, set);
|
||||
}
|
||||
set.add(cur);
|
||||
entryTable.put(cp, set);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -557,8 +557,8 @@ public class Package implements java.lang.reflect.AnnotatedElement {
|
||||
// First, update the system package map with new package names
|
||||
String[] names = getSystemPackages0();
|
||||
synchronized (pkgs) {
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
defineSystemPackage(names[i], getSystemPackage0(names[i]));
|
||||
for (String name : names) {
|
||||
defineSystemPackage(name, getSystemPackage0(name));
|
||||
}
|
||||
return pkgs.values().toArray(new Package[pkgs.size()]);
|
||||
}
|
||||
|
@ -1476,10 +1476,10 @@ class SecurityManager {
|
||||
/*
|
||||
* Traverse the list of packages, check for any matches.
|
||||
*/
|
||||
for (int i = 0; i < pkgs.length; i++) {
|
||||
if (pkg.startsWith(pkgs[i]) || pkgs[i].equals(pkg + ".")) {
|
||||
for (String restrictedPkg : pkgs) {
|
||||
if (pkg.startsWith(restrictedPkg) || restrictedPkg.equals(pkg + ".")) {
|
||||
checkPermission(
|
||||
new RuntimePermission("accessClassInPackage."+pkg));
|
||||
new RuntimePermission("accessClassInPackage." + pkg));
|
||||
break; // No need to continue; only need to check this once
|
||||
}
|
||||
}
|
||||
@ -1544,10 +1544,10 @@ class SecurityManager {
|
||||
/*
|
||||
* Traverse the list of packages, check for any matches.
|
||||
*/
|
||||
for (int i = 0; i < pkgs.length; i++) {
|
||||
if (pkg.startsWith(pkgs[i]) || pkgs[i].equals(pkg + ".")) {
|
||||
for (String restrictedPkg : pkgs) {
|
||||
if (pkg.startsWith(restrictedPkg) || restrictedPkg.equals(pkg + ".")) {
|
||||
checkPermission(
|
||||
new RuntimePermission("defineClassInPackage."+pkg));
|
||||
new RuntimePermission("defineClassInPackage." + pkg));
|
||||
break; // No need to continue; only need to check this once
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ class StringCoding {
|
||||
}
|
||||
|
||||
private static <T> void set(ThreadLocal<SoftReference<T>> tl, T ob) {
|
||||
tl.set(new SoftReference<T>(ob));
|
||||
tl.set(new SoftReference<>(ob));
|
||||
}
|
||||
|
||||
// Trim the given byte array to the given length
|
||||
|
@ -382,8 +382,7 @@ public class ThreadLocal<T> {
|
||||
setThreshold(len);
|
||||
table = new Entry[len];
|
||||
|
||||
for (int j = 0; j < len; j++) {
|
||||
Entry e = parentTable[j];
|
||||
for (Entry e : parentTable) {
|
||||
if (e != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ThreadLocal<Object> key = (ThreadLocal<Object>) e.get();
|
||||
@ -685,8 +684,7 @@ public class ThreadLocal<T> {
|
||||
Entry[] newTab = new Entry[newLen];
|
||||
int count = 0;
|
||||
|
||||
for (int j = 0; j < oldLen; ++j) {
|
||||
Entry e = oldTab[j];
|
||||
for (Entry e : oldTab) {
|
||||
if (e != null) {
|
||||
ThreadLocal<?> k = e.get();
|
||||
if (k == null) {
|
||||
|
@ -646,8 +646,7 @@ public class Throwable implements Serializable {
|
||||
private void printStackTrace(PrintStreamOrWriter s) {
|
||||
// Guard against malicious overrides of Throwable.equals by
|
||||
// using a Set with identity equality semantics.
|
||||
Set<Throwable> dejaVu =
|
||||
Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
|
||||
Set<Throwable> dejaVu = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
dejaVu.add(this);
|
||||
|
||||
synchronized (s.lock()) {
|
||||
|
@ -303,7 +303,7 @@ public class MethodHandleProxies {
|
||||
|
||||
private static
|
||||
Method[] getSingleNameMethods(Class<?> intfc) {
|
||||
ArrayList<Method> methods = new ArrayList<Method>();
|
||||
ArrayList<Method> methods = new ArrayList<>();
|
||||
String uniqueName = null;
|
||||
for (Method m : intfc.getMethods()) {
|
||||
if (isObjectMethod(m)) continue;
|
||||
|
@ -274,8 +274,8 @@ public class MutableCallSite extends CallSite {
|
||||
public static void syncAll(MutableCallSite[] sites) {
|
||||
if (sites.length == 0) return;
|
||||
STORE_BARRIER.lazySet(0);
|
||||
for (int i = 0; i < sites.length; i++) {
|
||||
sites[i].getClass(); // trigger NPE on first null
|
||||
for (MutableCallSite site : sites) {
|
||||
site.getClass(); // trigger NPE on first null
|
||||
}
|
||||
// FIXME: NYI
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ public class MemoryUsage {
|
||||
* Returns a descriptive representation of this memory usage.
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("init = " + init + "(" + (init >> 10) + "K) ");
|
||||
buf.append("used = " + used + "(" + (used >> 10) + "K) ");
|
||||
buf.append("committed = " + committed + "(" +
|
||||
|
@ -93,8 +93,8 @@ public class AccessibleObject implements AnnotatedElement {
|
||||
throws SecurityException {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) sm.checkPermission(ACCESS_PERMISSION);
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
setAccessible0(array[i], flag);
|
||||
for (AccessibleObject ao : array) {
|
||||
setAccessible0(ao, flag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,11 +337,9 @@ public final class Parameter implements AnnotatedElement {
|
||||
|
||||
private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
|
||||
if(null == declaredAnnotations) {
|
||||
declaredAnnotations =
|
||||
new HashMap<Class<? extends Annotation>, Annotation>();
|
||||
Annotation[] ann = getDeclaredAnnotations();
|
||||
for(int i = 0; i < ann.length; i++)
|
||||
declaredAnnotations.put(ann[i].annotationType(), ann[i]);
|
||||
declaredAnnotations = new HashMap<>();
|
||||
for (Annotation a : getDeclaredAnnotations())
|
||||
declaredAnnotations.put(a.annotationType(), a);
|
||||
}
|
||||
return declaredAnnotations;
|
||||
}
|
||||
|
@ -465,7 +465,7 @@ public class Proxy implements java.io.Serializable {
|
||||
Key2(Class<?> intf1, Class<?> intf2) {
|
||||
super(intf1);
|
||||
hash = 31 * intf1.hashCode() + intf2.hashCode();
|
||||
ref2 = new WeakReference<Class<?>>(intf2);
|
||||
ref2 = new WeakReference<>(intf2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -725,7 +725,6 @@ public class Proxy implements java.io.Serializable {
|
||||
}
|
||||
|
||||
final Constructor<?> cons = cl.getConstructor(constructorParams);
|
||||
final InvocationHandler ih = h;
|
||||
if (!Modifier.isPublic(cl.getModifiers())) {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
||||
public Void run() {
|
||||
@ -735,7 +734,7 @@ public class Proxy implements java.io.Serializable {
|
||||
});
|
||||
}
|
||||
return cons.newInstance(new Object[]{h});
|
||||
} catch (IllegalAccessException|InstantiationException e) {
|
||||
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException e) {
|
||||
throw new InternalError(e.toString(), e);
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable t = e.getCause();
|
||||
@ -744,8 +743,6 @@ public class Proxy implements java.io.Serializable {
|
||||
} else {
|
||||
throw new InternalError(t.toString(), t);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new InternalError(e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user