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

JDK-8218159: ValueBootstrapMethods.isSubstitutable should not filter synthetic fields #454

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -107,9 +107,9 @@ private static MethodHandle generateTarget(Lookup lookup, String name, MethodTyp

static MethodHandle[] getters(Class<?> type, Comparator<MethodHandle> comparator) {
Lookup lookup = new MethodHandles.Lookup(type.asPrimaryType());
// filter static fields and synthetic fields
// filter static fields
Stream<MethodHandle> s = Arrays.stream(type.getDeclaredFields())
.filter(f -> !Modifier.isStatic(f.getModifiers()) && !f.isSynthetic())
.filter(f -> !Modifier.isStatic(f.getModifiers()))
.map(f -> {
try {
return lookup.unreflectGetter(f);
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2021, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @run main Nest
* @summary Test substitutability of inner class and anonymous class that
* has the enclosing instance and possibly other captured outer locals
*/

public interface Nest {
public static void main(String... args) {
assertEquals(Nest.of(1, null), Nest.of(1, null));
assertNotEquals(Nest.of(1, null), Nest.of(2, null));

Outer n = new Outer(1);
Outer.Inner inner = n.new Inner(10);
Outer n1 = new Outer(1);
Outer n2 = new Outer(2);
assertEquals(n1.new Inner(10), inner);
assertEquals(n2.new Inner(10), new Outer(2).new Inner(10));
}

// o1.new Inner(1) == o2.new Inner(1) iff o1 == o2
static primitive class Outer {
final int i;
Outer(int i) {
this.i = i;
}

primitive class Inner {
final int ic;
Inner(int ic) {
this.ic = ic;
}
}
}

String toString();

static Nest of(int value, Object next) {
// anonymous class capturing outer locals
return new primitive Nest() {
public String toString() {
return value + " -> " + next;
}
};
}

static void assertEquals(Object o1, Object o2) {
if (o1 != o2) {
throw new RuntimeException(o1 + " != " + o2);
}
}
static void assertNotEquals(Object o1, Object o2) {
if (o1 == o2) {
throw new RuntimeException(o1 + " == " + o2);
}
}
}
@@ -178,9 +178,9 @@ public void testHashCode(Object o, int hash) {

private static Object[] hashCodeComponents(Object o) {
Class<?> type = o.getClass();
// filter static fields and synthetic fields
// filter static fields
Stream<Object> fields = Arrays.stream(type.getDeclaredFields())
.filter(f -> !Modifier.isStatic(f.getModifiers()) && !f.isSynthetic())
.filter(f -> !Modifier.isStatic(f.getModifiers()))
.map(f -> {
try {
return f.get(o);