8265418: Clean-up redundant null-checks of Class.getPackageName()
Reviewed-by: redestad
This commit is contained in:
parent
41185d38f2
commit
ae258f1e6a
src/java.base/share/classes
java
io
lang
util/concurrent/atomic
jdk/internal/reflect
sun
@ -1673,8 +1673,8 @@ public class ObjectStreamClass implements Serializable {
|
||||
* otherwise.
|
||||
*/
|
||||
private static boolean packageEquals(Class<?> cl1, Class<?> cl2) {
|
||||
return (cl1.getClassLoader() == cl2.getClassLoader() &&
|
||||
cl1.getPackageName().equals(cl2.getPackageName()));
|
||||
return cl1.getClassLoader() == cl2.getClassLoader() &&
|
||||
cl1.getPackageName() == cl2.getPackageName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3043,7 +3043,7 @@ public final class Class<T> implements java.io.Serializable,
|
||||
|
||||
if (ReflectUtil.needsPackageAccessCheck(ccl, cl)) {
|
||||
String pkg = this.getPackageName();
|
||||
if (pkg != null && !pkg.isEmpty()) {
|
||||
if (!pkg.isEmpty()) {
|
||||
// skip the package access check on a proxy class in default proxy package
|
||||
if (!Proxy.isProxyClass(this) || ReflectUtil.isNonPublicProxyClass(this)) {
|
||||
sm.checkPackageAccess(pkg);
|
||||
@ -3077,7 +3077,7 @@ public final class Class<T> implements java.io.Serializable,
|
||||
if (Proxy.isProxyClass(c))
|
||||
throw new InternalError("a permitted subclass should not be a proxy class: " + c);
|
||||
String pkg = c.getPackageName();
|
||||
if (pkg != null && !pkg.isEmpty()) {
|
||||
if (!pkg.isEmpty()) {
|
||||
packages.add(pkg);
|
||||
}
|
||||
}
|
||||
@ -3094,7 +3094,7 @@ public final class Class<T> implements java.io.Serializable,
|
||||
private String resolveName(String name) {
|
||||
if (!name.startsWith("/")) {
|
||||
String baseName = getPackageName();
|
||||
if (baseName != null && !baseName.isEmpty()) {
|
||||
if (!baseName.isEmpty()) {
|
||||
int len = baseName.length() + 1 + name.length();
|
||||
StringBuilder sb = new StringBuilder(len);
|
||||
name = sb.append(baseName.replace('.', '/'))
|
||||
|
@ -40,7 +40,6 @@ import java.lang.reflect.Modifier;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.Objects;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
@ -456,7 +455,7 @@ public abstract class AtomicIntegerFieldUpdater<T> {
|
||||
*/
|
||||
private static boolean isSamePackage(Class<?> class1, Class<?> class2) {
|
||||
return class1.getClassLoader() == class2.getClassLoader()
|
||||
&& Objects.equals(class1.getPackageName(), class2.getPackageName());
|
||||
&& class1.getPackageName() == class2.getPackageName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,6 @@ import java.lang.reflect.Modifier;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.Objects;
|
||||
import java.util.function.LongBinaryOperator;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
@ -656,6 +655,6 @@ public abstract class AtomicLongFieldUpdater<T> {
|
||||
*/
|
||||
static boolean isSamePackage(Class<?> class1, Class<?> class2) {
|
||||
return class1.getClassLoader() == class2.getClassLoader()
|
||||
&& Objects.equals(class1.getPackageName(), class2.getPackageName());
|
||||
&& class1.getPackageName() == class2.getPackageName();
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ import java.lang.reflect.Modifier;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.UnaryOperator;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
@ -397,7 +396,7 @@ public abstract class AtomicReferenceFieldUpdater<T,V> {
|
||||
*/
|
||||
private static boolean isSamePackage(Class<?> class1, Class<?> class2) {
|
||||
return class1.getClassLoader() == class2.getClassLoader()
|
||||
&& Objects.equals(class1.getPackageName(), class2.getPackageName());
|
||||
&& class1.getPackageName() == class2.getPackageName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,16 +33,14 @@ import java.io.OptionalDataException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Executable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
import jdk.internal.access.JavaLangReflectAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.misc.VM;
|
||||
@ -684,7 +682,7 @@ public class ReflectionFactory {
|
||||
}
|
||||
|
||||
return cl1.getClassLoader() == cl2.getClassLoader() &&
|
||||
Objects.equals(cl1.getPackageName(), cl2.getPackageName());
|
||||
cl1.getPackageName() == cl2.getPackageName();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ package sun.invoke.util;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import static java.lang.reflect.Modifier.*;
|
||||
import java.util.Objects;
|
||||
import jdk.internal.reflect.Reflection;
|
||||
|
||||
/**
|
||||
@ -375,7 +374,7 @@ public class VerifyAccess {
|
||||
return true;
|
||||
if (class1.getClassLoader() != class2.getClassLoader())
|
||||
return false;
|
||||
return Objects.equals(class1.getPackageName(), class2.getPackageName());
|
||||
return class1.getPackageName() == class2.getPackageName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,7 +129,7 @@ public final class ReflectUtil {
|
||||
}
|
||||
|
||||
String pkg = clazz.getPackageName();
|
||||
if (pkg != null && !pkg.isEmpty()) {
|
||||
if (!pkg.isEmpty()) {
|
||||
s.checkPackageAccess(pkg);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user