diff --git a/src/share/classes/com/sun/beans/finder/AbstractFinder.java b/src/share/classes/com/sun/beans/finder/AbstractFinder.java index 8ec9ffb7044ecfb67e4f691e798b97e46cc01f04..b7a6af88a3993b475c249292c543175efcc7fae3 100644 --- a/src/share/classes/com/sun/beans/finder/AbstractFinder.java +++ b/src/share/classes/com/sun/beans/finder/AbstractFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2013, 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 @@ -24,6 +24,9 @@ */ package com.sun.beans.finder; +import java.lang.reflect.Executable; +import java.lang.reflect.Modifier; + import java.util.HashMap; import java.util.Map; @@ -37,7 +40,7 @@ import java.util.Map; * * @author Sergey A. Malenkov */ -abstract class AbstractFinder { +abstract class AbstractFinder { private final Class[] args; /** @@ -52,27 +55,6 @@ abstract class AbstractFinder { this.args = args; } - /** - * Returns an array of {@code Class} objects - * that represent the formal parameter types of the method. - * Returns an empty array if the method takes no parameters. - * - * @param method the object that represents method - * @return the parameter types of the method - */ - protected abstract Class[] getParameters(T method); - - /** - * Returns {@code true} if and only if the method - * was declared to take a variable number of arguments. - * - * @param method the object that represents method - * @return {@code true} if the method was declared - * to take a variable number of arguments; - * {@code false} otherwise - */ - protected abstract boolean isVarArgs(T method); - /** * Checks validness of the method. * At least the valid method should be public. @@ -81,7 +63,9 @@ abstract class AbstractFinder { * @return {@code true} if the method is valid, * {@code false} otherwise */ - protected abstract boolean isValid(T method); + protected boolean isValid(T method) { + return Modifier.isPublic(method.getModifiers()); + } /** * Performs a search in the {@code methods} array. @@ -109,7 +93,7 @@ abstract class AbstractFinder { for (T newMethod : methods) { if (isValid(newMethod)) { - Class[] newParams = getParameters(newMethod); + Class[] newParams = newMethod.getParameterTypes(); if (newParams.length == this.args.length) { PrimitiveWrapperMap.replacePrimitivesWithWrappers(newParams); if (isAssignable(newParams, this.args)) { @@ -120,6 +104,11 @@ abstract class AbstractFinder { boolean useNew = isAssignable(oldParams, newParams); boolean useOld = isAssignable(newParams, oldParams); + if (useOld && useNew) { + // only if parameters are equal + useNew = !newMethod.isSynthetic(); + useOld = !oldMethod.isSynthetic(); + } if (useOld == useNew) { ambiguous = true; } else if (useNew) { @@ -130,7 +119,7 @@ abstract class AbstractFinder { } } } - if (isVarArgs(newMethod)) { + if (newMethod.isVarArgs()) { int length = newParams.length - 1; if (length <= this.args.length) { Class[] array = new Class[this.args.length]; @@ -160,6 +149,11 @@ abstract class AbstractFinder { boolean useNew = isAssignable(oldParams, newParams); boolean useOld = isAssignable(newParams, oldParams); + if (useOld && useNew) { + // only if parameters are equal + useNew = !newMethod.isSynthetic(); + useOld = !oldMethod.isSynthetic(); + } if (useOld == useNew) { if (oldParams == map.get(oldMethod)) { ambiguous = true; diff --git a/src/share/classes/com/sun/beans/finder/ConstructorFinder.java b/src/share/classes/com/sun/beans/finder/ConstructorFinder.java index f7419c7973af7aafc68e9f710730f2fabd030ebe..1de6b0a8263fe1f91a8478df65faab3785e8af7b 100644 --- a/src/share/classes/com/sun/beans/finder/ConstructorFinder.java +++ b/src/share/classes/com/sun/beans/finder/ConstructorFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2013, 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 @@ -86,44 +86,4 @@ public final class ConstructorFinder extends AbstractFinder> { private ConstructorFinder(Class[] args) { super(args); } - - /** - * Returns an array of {@code Class} objects - * that represent the formal parameter types of the constructor. - * Returns an empty array if the constructor takes no parameters. - * - * @param constructor the object that represents constructor - * @return the parameter types of the constructor - */ - @Override - protected Class[] getParameters(Constructor constructor) { - return constructor.getParameterTypes(); - } - - /** - * Returns {@code true} if and only if the constructor - * was declared to take a variable number of arguments. - * - * @param constructor the object that represents constructor - * @return {@code true} if the constructor was declared - * to take a variable number of arguments; - * {@code false} otherwise - */ - @Override - protected boolean isVarArgs(Constructor constructor) { - return constructor.isVarArgs(); - } - - /** - * Checks validness of the constructor. - * The valid constructor should be public. - * - * @param constructor the object that represents constructor - * @return {@code true} if the constructor is valid, - * {@code false} otherwise - */ - @Override - protected boolean isValid(Constructor constructor) { - return Modifier.isPublic(constructor.getModifiers()); - } } diff --git a/src/share/classes/com/sun/beans/finder/MethodFinder.java b/src/share/classes/com/sun/beans/finder/MethodFinder.java index 98c52bc929a42c14b77450093db8ef014a927284..83a3cedbf3371e4edecfa697eca7606e38cf2936 100644 --- a/src/share/classes/com/sun/beans/finder/MethodFinder.java +++ b/src/share/classes/com/sun/beans/finder/MethodFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2013, 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 @@ -195,33 +195,6 @@ public final class MethodFinder extends AbstractFinder { this.name = name; } - /** - * Returns an array of {@code Class} objects - * that represent the formal parameter types of the method. - * Returns an empty array if the method takes no parameters. - * - * @param method the object that represents method - * @return the parameter types of the method - */ - @Override - protected Class[] getParameters(Method method) { - return method.getParameterTypes(); - } - - /** - * Returns {@code true} if and only if the method - * was declared to take a variable number of arguments. - * - * @param method the object that represents method - * @return {@code true} if the method was declared - * to take a variable number of arguments; - * {@code false} otherwise - */ - @Override - protected boolean isVarArgs(Method method) { - return method.isVarArgs(); - } - /** * Checks validness of the method. * The valid method should be public and @@ -233,6 +206,6 @@ public final class MethodFinder extends AbstractFinder { */ @Override protected boolean isValid(Method method) { - return !method.isBridge() && Modifier.isPublic(method.getModifiers()) && method.getName().equals(this.name); + return super.isValid(method) && method.getName().equals(this.name); } } diff --git a/test/java/beans/XMLEncoder/Test8013416.java b/test/java/beans/XMLEncoder/Test8013416.java new file mode 100644 index 0000000000000000000000000000000000000000..bcc345744ff2ca915e612b716ef31322a61947b6 --- /dev/null +++ b/test/java/beans/XMLEncoder/Test8013416.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2013, 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 + * @bug 8013416 + * @summary Tests public synthetic methods + * @author Sergey Malenkov + */ + +import java.beans.DefaultPersistenceDelegate; +import java.beans.Encoder; +import java.beans.Expression; +import java.beans.Statement; +import java.beans.XMLEncoder; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Set; + +public class Test8013416 extends AbstractTest { + public static void main(String[] args) { + new Test8013416().test(true); + } + + protected Object getObject() { + Public map = new Public(); + map.put(" pz1 ", " pz2 "); + map.put(" pz3 ", " pz4 "); + return map; + } + + @Override + protected void initialize(XMLEncoder encoder) { + super.initialize(encoder); + encoder.setPersistenceDelegate(Public.class, new PublicPersistenceDelegate()); + } + + private static final class PublicPersistenceDelegate extends DefaultPersistenceDelegate { + @Override + protected Expression instantiate(Object oldInstance, Encoder out) { + return new Expression(oldInstance, oldInstance.getClass(), "new", null); + } + + @Override + protected void initialize(Class type, Object oldInstance, Object newInstance, Encoder out) { + super.initialize(type, oldInstance, newInstance, out); + + Public map = (Public) oldInstance; + for (Entry entry : map.getAll()) { + String[] args = {entry.getKey(), entry.getValue()}; + out.writeStatement(new Statement(oldInstance, "put", args)); + } + } + } + + public static final class Public extends Private { + } + + private static class Private { + private HashMap map = new HashMap(); + + public void put(K key, V value) { + this.map.put(key, value); + } + + public Set> getAll() { + return this.map.entrySet(); + } + } +}