--- old/src/java.base/share/classes/jdk/internal/reflect/Reflection.java 2018-05-14 22:51:53.889303386 -0400 +++ new/src/java.base/share/classes/jdk/internal/reflect/Reflection.java 2018-05-14 22:51:52.401217406 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2018, 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 @@ -143,6 +143,17 @@ return true; } + // Check for nestmate access if member is private + if (Modifier.isPrivate(modifiers)) { + // assert: isSubclassof(targetClass, memberClass) + // Note: targetClass may be outside the nest, but that is okay + // as long as memberClass is in the nest. + boolean nestmates = areNestMates(currentClass, memberClass); + if (nestmates) { + return true; + } + } + boolean successSoFar = false; if (Modifier.isProtected(modifiers)) { @@ -351,4 +362,12 @@ return new IllegalAccessException(msg); } + + /** + * Returns true if {@code currentClass} and {@code memberClass} + * are nestmates - that is, if they have the same nesthost as + * determined by the VM. + */ + public static native boolean areNestMates(Class currentClass, + Class memberClass); }