mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8280035: Use Class.isInstance instead of Class.isAssignableFrom where applicable
Reviewed-by: prr, rriggs
This commit is contained in:
parent
9f562ef754
commit
de74e0e25a
10 changed files with 22 additions and 25 deletions
|
@ -481,7 +481,7 @@ public class AccessibleObject implements AnnotatedElement {
|
||||||
}
|
}
|
||||||
// if this object is an instance member, the given object
|
// if this object is an instance member, the given object
|
||||||
// must be a subclass of the declaring class of this reflected object
|
// must be a subclass of the declaring class of this reflected object
|
||||||
if (!declaringClass.isAssignableFrom(obj.getClass())) {
|
if (!declaringClass.isInstance(obj)) {
|
||||||
throw new IllegalArgumentException("object is not an instance of "
|
throw new IllegalArgumentException("object is not an instance of "
|
||||||
+ declaringClass.getName());
|
+ declaringClass.getName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2001, 2022, 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
|
||||||
|
@ -77,7 +77,7 @@ class UnsafeObjectFieldAccessorImpl extends UnsafeFieldAccessorImpl {
|
||||||
throwFinalFieldIllegalAccessException(value);
|
throwFinalFieldIllegalAccessException(value);
|
||||||
}
|
}
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
if (!field.getType().isAssignableFrom(value.getClass())) {
|
if (!field.getType().isInstance(value)) {
|
||||||
throwSetIllegalArgumentException(value);
|
throwSetIllegalArgumentException(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2004, 2022, 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
|
||||||
|
@ -79,7 +79,7 @@ class UnsafeQualifiedObjectFieldAccessorImpl
|
||||||
throwFinalFieldIllegalAccessException(value);
|
throwFinalFieldIllegalAccessException(value);
|
||||||
}
|
}
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
if (!field.getType().isAssignableFrom(value.getClass())) {
|
if (!field.getType().isInstance(value)) {
|
||||||
throwSetIllegalArgumentException(value);
|
throwSetIllegalArgumentException(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2004, 2022, 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
|
||||||
|
@ -77,7 +77,7 @@ class UnsafeQualifiedStaticObjectFieldAccessorImpl
|
||||||
throwFinalFieldIllegalAccessException(value);
|
throwFinalFieldIllegalAccessException(value);
|
||||||
}
|
}
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
if (!field.getType().isAssignableFrom(value.getClass())) {
|
if (!field.getType().isInstance(value)) {
|
||||||
throwSetIllegalArgumentException(value);
|
throwSetIllegalArgumentException(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2001, 2022, 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
|
||||||
|
@ -75,7 +75,7 @@ class UnsafeStaticObjectFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl
|
||||||
throwFinalFieldIllegalAccessException(value);
|
throwFinalFieldIllegalAccessException(value);
|
||||||
}
|
}
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
if (!field.getType().isAssignableFrom(value.getClass())) {
|
if (!field.getType().isInstance(value)) {
|
||||||
throwSetIllegalArgumentException(value);
|
throwSetIllegalArgumentException(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2008, 2022, 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
|
||||||
|
@ -188,7 +188,7 @@ class NewElementHandler extends ElementHandler {
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
Class<?> type = types[index];
|
Class<?> type = types[index];
|
||||||
if (type.isAssignableFrom(argument.getClass())) {
|
if (type.isInstance(argument)) {
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2022, 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 @@
|
||||||
|
|
||||||
package javax.imageio.spi;
|
package javax.imageio.spi;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.security.AccessControlContext;
|
import java.security.AccessControlContext;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
|
@ -228,7 +227,7 @@ public class ServiceRegistry {
|
||||||
private Iterator<SubRegistry> getSubRegistries(Object provider) {
|
private Iterator<SubRegistry> getSubRegistries(Object provider) {
|
||||||
List<SubRegistry> l = new ArrayList<>();
|
List<SubRegistry> l = new ArrayList<>();
|
||||||
for (Class<?> c : categoryMap.keySet()) {
|
for (Class<?> c : categoryMap.keySet()) {
|
||||||
if (c.isAssignableFrom(provider.getClass())) {
|
if (c.isInstance(provider)) {
|
||||||
l.add(categoryMap.get(c));
|
l.add(categoryMap.get(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,7 +269,7 @@ public class ServiceRegistry {
|
||||||
if (reg == null) {
|
if (reg == null) {
|
||||||
throw new IllegalArgumentException("category unknown!");
|
throw new IllegalArgumentException("category unknown!");
|
||||||
}
|
}
|
||||||
if (!category.isAssignableFrom(provider.getClass())) {
|
if (!category.isInstance(provider)) {
|
||||||
throw new ClassCastException();
|
throw new ClassCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,7 +372,7 @@ public class ServiceRegistry {
|
||||||
if (reg == null) {
|
if (reg == null) {
|
||||||
throw new IllegalArgumentException("category unknown!");
|
throw new IllegalArgumentException("category unknown!");
|
||||||
}
|
}
|
||||||
if (!category.isAssignableFrom(provider.getClass())) {
|
if (!category.isInstance(provider)) {
|
||||||
throw new ClassCastException();
|
throw new ClassCastException();
|
||||||
}
|
}
|
||||||
return reg.deregisterServiceProvider(provider);
|
return reg.deregisterServiceProvider(provider);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, 2022, 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,14 +50,12 @@ import java.awt.image.BufferedImage;
|
||||||
import static java.awt.image.BufferedImage.*;
|
import static java.awt.image.BufferedImage.*;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
|
@ -565,7 +563,7 @@ ${UI_DEFAULT_INIT}
|
||||||
//type registered, then check to make sure c is of the
|
//type registered, then check to make sure c is of the
|
||||||
//right type;
|
//right type;
|
||||||
Class<?> clazz = parts[partIndex].c;
|
Class<?> clazz = parts[partIndex].c;
|
||||||
if (clazz != null && clazz.isAssignableFrom(c.getClass())) {
|
if (clazz != null && clazz.isInstance(c)) {
|
||||||
//so far so good, recurse
|
//so far so good, recurse
|
||||||
return matches(c.getParent(), partIndex - 1);
|
return matches(c.getParent(), partIndex - 1);
|
||||||
} else if (clazz == null &&
|
} else if (clazz == null &&
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2004, 2022, 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
|
||||||
|
@ -140,7 +140,7 @@ public class Utils {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (Object o : c) {
|
for (Object o : c) {
|
||||||
if (o == null || !e.isAssignableFrom(o.getClass())) {
|
if (o == null || !e.isInstance(o)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2022, 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
|
||||||
|
@ -401,8 +401,8 @@ public final class TypeLibrary {
|
||||||
Class<?> ct = returnType.getComponentType();
|
Class<?> ct = returnType.getComponentType();
|
||||||
if (Annotation.class.isAssignableFrom(ct) && ct.getAnnotation(Repeatable.class) != null) {
|
if (Annotation.class.isAssignableFrom(ct) && ct.getAnnotation(Repeatable.class) != null) {
|
||||||
Object res = m.invoke(a, new Object[0]);
|
Object res = m.invoke(a, new Object[0]);
|
||||||
if (res != null && Annotation[].class.isAssignableFrom(res.getClass())) {
|
if (res instanceof Annotation[] anns) {
|
||||||
for (Annotation rep : (Annotation[]) m.invoke(a, new Object[0])) {
|
for (Annotation rep : anns) {
|
||||||
annos.add(rep);
|
annos.add(rep);
|
||||||
}
|
}
|
||||||
repeated = true;
|
repeated = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue