Skip to content
Permalink
Browse files
JCLOUDS-1542 follow-up: check whether isAccessible() is already set (#79
)

AccessibleObject.canAccess() would be much much better,
but this API can only be used from Java 9 onward.
  • Loading branch information
JnRouvignac committed Jul 5, 2020
1 parent 238c975 commit 9e4c7a16daeb97f9b51b9077e40d12ce5343840f
Showing 1 changed file with 6 additions and 3 deletions.
@@ -155,7 +155,8 @@ public static <T> Collection<Invokable<T, Object>> methods(Class<T> ownerType) {
ImmutableSet.Builder<Invokable<?, ?>> builder = ImmutableSet.<Invokable<?, ?>> builder();
Class<?> raw = key.getRawType();
for (Constructor<?> ctor : raw.getDeclaredConstructors()) {
if (!coreJavaClass(raw)) {
// TODO replace isAccessible() with canAccess() when using Java >= 9
if (!ctor.isAccessible() && !coreJavaClass(raw)) {
// In JDK 11 up to 14, the only uses for `java.beans.ConstructorProperties` annotation
// are in the `java.awt`, `java.beans` and `javax.swing` packages.
// Since these constructors are public, there is no need to call `setAccessible()`
@@ -167,7 +168,8 @@ public static <T> Collection<Invokable<T, Object>> methods(Class<T> ownerType) {
if (Modifier.isAbstract(raw.getModifiers())) {
for (Invokable<?, Object> method : methods(raw)){
if (method.isStatic() && method.getReturnType().equals(key)) {
if (!coreJavaClass(raw)) {
// TODO replace isAccessible() with canAccess() when using Java >= 9
if (!method.isAccessible() && !coreJavaClass(raw)) {
method.setAccessible(true);
}
builder.add(method);
@@ -325,7 +327,8 @@ public String toString() {
if (raw == Object.class)
continue;
for (Method method : raw.getDeclaredMethods()) {
if (!coreJavaClass(raw)) {
// TODO replace isAccessible() with canAccess() when using Java >= 9
if (!method.isAccessible() && !coreJavaClass(raw)) {
method.setAccessible(true);
}
builder.add(key.method(method));

0 comments on commit 9e4c7a1

Please sign in to comment.