Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8199149: Improve the exception message thrown by VarHandle of unsupported operation #14928

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -90,9 +90,7 @@ public VarHandle withInvokeBehavior() {
@Override
@ForceInline
boolean checkAccessModeThenIsDirect(VarHandle.AccessDescriptor ad) {
if (exact && accessModeType(ad.type) != ad.symbolicMethodTypeExact) {
throwWrongMethodTypeException(ad);
}
super.checkAccessModeThenIsDirect(ad);
// return false to indicate this is an IndirectVarHandle
return false;
}
15 changes: 3 additions & 12 deletions src/java.base/share/classes/java/lang/invoke/VarHandle.java
Original file line number Diff line number Diff line change
@@ -2006,18 +2006,9 @@ public static AccessMode valueFromMethodName(String methodName) {
};
}

// Mapping from the ordinal to AccessMode
private static final Map<Integer, AccessMode> modeToAccessMode = initOrdinalToAccessModeMap();
private static Map<Integer, AccessMode> initOrdinalToAccessModeMap() {
Map<Integer, AccessMode> map = new HashMap<>();
for (AccessMode am : AccessMode.values()) {
map.put(am.ordinal(), am);
}
return map;
}

private static final @Stable AccessMode[] VALUES = values();
static AccessMode valueFromOrdinal(int mode) {
return modeToAccessMode.get(mode);
return VALUES[mode];
}
}

@@ -2110,7 +2101,7 @@ public final MethodType accessModeType(AccessMode accessMode) {
*/
@ForceInline
boolean checkAccessModeThenIsDirect(VarHandle.AccessDescriptor ad) {
if (vform.getMemberNameOrNull(ad.mode) == null) {
if (!isAccessModeSupported(AccessMode.valueFromOrdinal(ad.mode))) {
throwUnsupportedOperationException(ad.mode);
}
if (exact && accessModeType(ad.type) != ad.symbolicMethodTypeExact) {