--- old/src/java.base/share/classes/jdk/internal/reflect/Reflection.java 2018-05-22 05:54:55.676147520 -0400 +++ new/src/java.base/share/classes/jdk/internal/reflect/Reflection.java 2018-05-22 05:54:54.152059223 -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,16 @@ 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. + if (areNestMates(currentClass, memberClass)) { + return true; + } + } + boolean successSoFar = false; if (Modifier.isProtected(modifiers)) { @@ -351,4 +361,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); }