Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -1576,10 +1576,8 @@ boolean isPartial() {
}

private static Class<?> toClass(Type o) {
if (o instanceof GenericArrayType)
return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()),
0)
.getClass();
if (o instanceof GenericArrayType gat)
return toClass(gat.getGenericComponentType()).arrayType();
return (Class<?>)o;
}

Expand Down Expand Up @@ -3000,8 +2998,8 @@ public InputStream getResourceAsStream(String name) {
// need for a URL connection
if (cl == null) {
return BootLoader.findResourceAsStream(mn, name);
} else if (cl instanceof BuiltinClassLoader) {
return ((BuiltinClassLoader) cl).findResourceAsStream(mn, name);
} else if (cl instanceof BuiltinClassLoader bcl) {
return bcl.findResourceAsStream(mn, name);
} else {
URL url = cl.findResource(mn, name);
return (url != null) ? url.openStream() : null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -124,8 +124,8 @@ static BoundMethodHandle makeReinvoker(MethodHandle target) {
/*non-public*/
static BoundMethodHandle.SpeciesData speciesDataFor(LambdaForm form) {
Object c = form.names[0].constraint;
if (c instanceof SpeciesData) {
return (SpeciesData) c;
if (c instanceof SpeciesData sd) {
return sd;
}
// if there is no BMH constraint, then use the null constraint
return SPECIALIZER.topSpecies();
Expand Down Expand Up @@ -153,8 +153,8 @@ final String internalValues(int indentLevel) {
for (int i = 0; i < count; ++i) {
Object theArg = arg(i);
sb.append("\n ").append(prefix).append(i);
if (indentLevel >= 0 && theArg instanceof MethodHandle) {
sb.append(": MethodHandle = {").append(((MethodHandle)theArg).debugString(indentLevel+1));
if (indentLevel >= 0 && theArg instanceof MethodHandle mh) {
sb.append(": MethodHandle = {").append(mh.debugString(indentLevel+1));
sb.append("\n ").append(prefix).append("}");
} else {
sb.append(": ( ").append(theArg).append(" )");
Expand Down
6 changes: 3 additions & 3 deletions src/java.base/share/classes/java/lang/invoke/CallSite.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -315,8 +315,8 @@ static CallSite makeSite(MethodHandle bootstrapMethod,
try {
Object binding = BootstrapMethodInvoker.invoke(
CallSite.class, bootstrapMethod, name, type, info, callerClass);
if (binding instanceof CallSite) {
site = (CallSite) binding;
if (binding instanceof CallSite cs) {
site = cs;
} else {
// See the "Linking Exceptions" section for the invokedynamic
// instruction in JVMS 6.5.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,10 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (!(obj instanceof ClassSpecializer.SpeciesData)) {
if (!(obj instanceof ClassSpecializer<?, ?, ?>.SpeciesData that)) {
return false;
}
@SuppressWarnings("rawtypes")
ClassSpecializer.SpeciesData that = (ClassSpecializer.SpeciesData) obj;

return this.outer() == that.outer() && this.key.equals(that.key);
}

Expand Down Expand Up @@ -656,8 +655,8 @@ <X> List<Var> fromTypes(List<X> types) {
for (X x : types) {
String vn = name;
Class<?> vt;
if (x instanceof Class) {
vt = (Class<?>) x;
if (x instanceof Class<?> cl) {
vt = cl;
// make the names friendlier if debugging
assert((vn = vn + "_" + (i++)) != null);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,9 +27,7 @@

import java.security.*;
import java.lang.reflect.*;
import java.lang.invoke.MethodHandleNatives.Constants;
import java.lang.invoke.MethodHandles.Lookup;
import static java.lang.invoke.MethodHandleStatics.*;

/*
* Auxiliary to MethodHandleInfo, wants to nest in MethodHandleInfo but must be non-public.
Expand Down Expand Up @@ -132,11 +130,11 @@ private Member reflectUnchecked() throws ReflectiveOperationException {
}

private static MemberName convertToMemberName(byte refKind, Member mem) throws IllegalAccessException {
if (mem instanceof Method) {
if (mem instanceof Method mth) {
boolean wantSpecial = (refKind == REF_invokeSpecial);
return new MemberName((Method) mem, wantSpecial);
} else if (mem instanceof Constructor) {
return new MemberName((Constructor) mem);
return new MemberName(mth, wantSpecial);
} else if (mem instanceof Constructor<?> ctor) {
return new MemberName(ctor);
} else if (mem instanceof Field) {
boolean isSetter = (refKind == REF_putField || refKind == REF_putStatic);
return new MemberName((Field) mem, isSetter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,8 @@ void addMethod() {
case SELECT_ALTERNATIVE:
assert lambdaForm.isSelectAlternative(i);
if (PROFILE_GWT) {
assert(name.arguments[0] instanceof Name &&
((Name)name.arguments[0]).refersTo(MethodHandleImpl.class, "profileBoolean"));
assert(name.arguments[0] instanceof Name n &&
n.refersTo(MethodHandleImpl.class, "profileBoolean"));
mv.visitAnnotation(INJECTEDPROFILE_SIG, true);
}
onStack = emitSelectAlternative(name, lambdaForm.names[i+1]);
Expand Down
3 changes: 1 addition & 2 deletions src/java.base/share/classes/java/lang/invoke/Invokers.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import jdk.internal.vm.annotation.Hidden;
import jdk.internal.vm.annotation.Stable;

import java.lang.reflect.Array;
import java.util.Arrays;

import static java.lang.invoke.MethodHandleStatics.*;
Expand Down Expand Up @@ -244,7 +243,7 @@ private static Class<?> impliedRestargType(MethodType restargType, int fromPos)
throw newIllegalArgumentException("need homogeneous rest arguments", restargType);
}
if (argType == Object.class) return Object[].class;
return Array.newInstance(argType, 0).getClass();
return argType.arrayType();
}

public String toString() {
Expand Down
18 changes: 9 additions & 9 deletions src/java.base/share/classes/java/lang/invoke/LambdaForm.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -949,8 +949,8 @@ Object interpretName(Name name, Object[] values) throws Throwable {
Object[] arguments = Arrays.copyOf(name.arguments, name.arguments.length, Object[].class);
for (int i = 0; i < arguments.length; i++) {
Object a = arguments[i];
if (a instanceof Name) {
int i2 = ((Name)a).index();
if (a instanceof Name n) {
int i2 = n.index();
assert(names[i2] == a);
a = values[i2];
arguments[i] = a;
Expand Down Expand Up @@ -1061,7 +1061,7 @@ String debugString(int indentLevel) {

@Override
public boolean equals(Object obj) {
return obj instanceof LambdaForm && equals((LambdaForm)obj);
return obj instanceof LambdaForm lf && equals(lf);
}
public boolean equals(LambdaForm that) {
if (this.result != that.result) return false;
Expand Down Expand Up @@ -1362,7 +1362,7 @@ private Name(Name that, Object constraint) {
}
Name(MethodType functionType, Object... arguments) {
this(new NamedFunction(functionType), arguments);
assert(arguments[0] instanceof Name && ((Name)arguments[0]).type == L_TYPE);
assert(arguments[0] instanceof Name name && name.type == L_TYPE);
}
Name(MemberName function, Object... arguments) {
this(new NamedFunction(function), arguments);
Expand Down Expand Up @@ -1524,7 +1524,7 @@ public String paramString() {
Object c = constraint;
if (c == null)
return s;
if (c instanceof Class) c = ((Class<?>)c).getSimpleName();
if (c instanceof Class<?> cl) c = cl.getSimpleName();
return s + "/" + c;
}
public String exprString() {
Expand Down Expand Up @@ -1556,8 +1556,8 @@ private boolean typesMatch(NamedFunction function, Object ... arguments) {
}

private static boolean typesMatch(BasicType parameterType, Object object) {
if (object instanceof Name) {
return ((Name)object).type == parameterType;
if (object instanceof Name name) {
return name.type == parameterType;
}
switch (parameterType) {
case I_TYPE: return object instanceof Integer;
Expand Down Expand Up @@ -1608,7 +1608,7 @@ public boolean equals(Name that) {
}
@Override
public boolean equals(Object x) {
return x instanceof Name && equals((Name)x);
return x instanceof Name n && equals(n);
}
@Override
public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -101,10 +101,10 @@ private Transform(long packedBytes, byte[] fullBytes, LambdaForm result) {

@Override
public boolean equals(Object obj) {
if (obj instanceof TransformKey) {
return equals((TransformKey) obj);
if (obj instanceof TransformKey key) {
return equals(key);
}
return obj instanceof Transform && equals((Transform)obj);
return obj instanceof Transform transform && equals(transform);
}

private boolean equals(TransformKey that) {
Expand Down Expand Up @@ -354,10 +354,10 @@ public String toString() {

@Override
public boolean equals(Object obj) {
if (obj instanceof TransformKey) {
return equals((TransformKey) obj);
if (obj instanceof TransformKey key) {
return equals(key);
}
return obj instanceof Transform && equals((Transform)obj);
return obj instanceof Transform transform && equals(transform);
}

private boolean equals(TransformKey that) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -34,7 +34,7 @@ final class LambdaProxyClassArchive {
*/
static boolean loadedByBuiltinLoader(Class<?> cls) {
ClassLoader cl = cls.getClassLoader();
return (cl == null || (cl instanceof BuiltinClassLoader)) ? true : false;
return cl == null || (cl instanceof BuiltinClassLoader);
}

private static native void addToArchive(Class<?> caller,
Expand Down
34 changes: 17 additions & 17 deletions src/java.base/share/classes/java/lang/invoke/MemberName.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -135,8 +135,8 @@ public MethodType getMethodType() {
{
// Get a snapshot of type which doesn't get changed by racing threads.
final Object type = this.type;
if (type instanceof MethodType) {
return (MethodType) type;
if (type instanceof MethodType mt) {
return mt;
}
}

Expand Down Expand Up @@ -173,8 +173,8 @@ String getMethodDescriptor() {

// Get a snapshot of type which doesn't get changed by racing threads.
final Object type = this.type;
if (type instanceof String) {
return (String) type;
if (type instanceof String str) {
return str;
} else {
return getMethodType().toMethodDescriptorString();
}
Expand Down Expand Up @@ -211,8 +211,8 @@ public Class<?> getFieldType() {
{
// Get a snapshot of type which doesn't get changed by racing threads.
final Object type = this.type;
if (type instanceof Class<?>) {
return (Class<?>) type;
if (type instanceof Class<?> cl) {
return cl;
}
}

Expand Down Expand Up @@ -725,7 +725,7 @@ public int hashCode() {

@Override
public boolean equals(Object that) {
return (that instanceof MemberName && this.equals((MemberName)that));
return that instanceof MemberName mn && this.equals(mn);
}

/** Decide if two member names have exactly the same symbolic content.
Expand Down Expand Up @@ -808,17 +808,17 @@ void initResolved(boolean isResolved) {
void checkForTypeAlias(Class<?> refc) {
if (isInvocable()) {
MethodType type;
if (this.type instanceof MethodType)
type = (MethodType) this.type;
if (this.type instanceof MethodType mt)
type = mt;
else
this.type = type = getMethodType();
if (type.erase() == type) return;
if (VerifyAccess.isTypeVisible(type, refc)) return;
throw new LinkageError("bad method type alias: "+type+" not visible from "+refc);
} else {
Class<?> type;
if (this.type instanceof Class<?>)
type = (Class<?>) this.type;
if (this.type instanceof Class<?> cl)
type = cl;
else
this.type = type = getFieldType();
if (VerifyAccess.isTypeVisible(type, refc)) return;
Expand Down Expand Up @@ -863,8 +863,8 @@ public String toString() {
return buf.toString();
}
private static String getName(Object obj) {
if (obj instanceof Class<?>)
return ((Class<?>)obj).getName();
if (obj instanceof Class<?> cl)
return cl.getName();
return String.valueOf(obj);
}

Expand Down Expand Up @@ -915,8 +915,8 @@ else if (isMethod())
ex = new NoSuchMethodException(message);
else
ex = new NoSuchFieldException(message);
if (resolution instanceof Throwable)
ex.initCause((Throwable) resolution);
if (resolution instanceof Throwable res)
ex.initCause(res);
return ex;
}

Expand Down Expand Up @@ -992,7 +992,7 @@ MemberName resolveOrFail(byte refKind, MemberName m,
if (result.isResolved())
return result;
ReflectiveOperationException ex = result.makeAccessException();
if (ex instanceof IllegalAccessException) throw (IllegalAccessException) ex;
if (ex instanceof IllegalAccessException iae) throw iae;
throw nsmClass.cast(ex);
}
/** Produce a resolved version of the given member.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ static void checkSpreadArgument(Object av, int n) {
return;
} else if (av == null) {
throw new NullPointerException("null array reference");
} else if (av instanceof Object[]) {
int len = ((Object[])av).length;
} else if (av instanceof Object[] array) {
int len = array.length;
if (len == n) return;
} else {
int len = java.lang.reflect.Array.getLength(av);
Expand Down
Loading