8279242: Reflection newInstance() error message when constructor has no access modifiers could use improvement
Reviewed-by: iris, dholmes, mchung
This commit is contained in:
parent
841eae6f52
commit
295c0474c4
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2020, 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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -379,11 +379,8 @@ public class Reflection {
|
||||
|
||||
String msg = currentClass + currentSuffix + " cannot access ";
|
||||
if (m2.isExported(memberPackageName, m1)) {
|
||||
|
||||
// module access okay so include the modifiers in the message
|
||||
msg += "a member of " + memberClass + memberSuffix +
|
||||
" with modifiers \"" + Modifier.toString(modifiers) + "\"";
|
||||
|
||||
msg += "a member of " + memberClass + memberSuffix + msgSuffix(modifiers);
|
||||
} else {
|
||||
// module access failed
|
||||
msg += memberClass + memberSuffix+ " because "
|
||||
@ -410,11 +407,8 @@ public class Reflection {
|
||||
|
||||
String msg = "JNI attached native thread (null caller frame) cannot access ";
|
||||
if (m2.isExported(memberPackageName)) {
|
||||
|
||||
// module access okay so include the modifiers in the message
|
||||
msg += "a member of " + memberClass + memberSuffix +
|
||||
" with modifiers \"" + Modifier.toString(modifiers) + "\"";
|
||||
|
||||
msg += "a member of " + memberClass + memberSuffix + msgSuffix(modifiers);
|
||||
} else {
|
||||
// module access failed
|
||||
msg += memberClass + memberSuffix+ " because "
|
||||
@ -424,6 +418,16 @@ public class Reflection {
|
||||
return new IllegalAccessException(msg);
|
||||
}
|
||||
|
||||
private static String msgSuffix(int modifiers) {
|
||||
boolean packageAccess =
|
||||
((Modifier.PRIVATE |
|
||||
Modifier.PROTECTED |
|
||||
Modifier.PUBLIC) & modifiers) == 0;
|
||||
return packageAccess ?
|
||||
" with package access" :
|
||||
" with modifiers \"" + Modifier.toString(modifiers) + "\"";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if {@code currentClass} and {@code memberClass}
|
||||
* are nestmates - that is, if they have the same nesthost as
|
||||
|
Loading…
Reference in New Issue
Block a user