jdk/src/share/classes/com/sun/beans/finder/AbstractFinder.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -22,10 +22,13 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 package com.sun.beans.finder;
 
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+
 import java.util.HashMap;
 import java.util.Map;
 
 /**
  * This abstract class provides functionality

@@ -35,11 +38,11 @@
  *
  * @since 1.7
  *
  * @author Sergey A. Malenkov
  */
-abstract class AbstractFinder<T> {
+abstract class AbstractFinder<T extends Member> {
     private final Class<?>[] args;
 
     /**
      * Creates finder for array of classes of arguments.
      * If a particular element of array equals {@code null},

@@ -79,11 +82,13 @@
      *
      * @param method  the object that represents method
      * @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.
      * The one method is selected from the array of the valid methods.
      * The list of parameters of the selected method shows

@@ -118,10 +123,15 @@
                             oldParams = newParams;
                         } else {
                             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) {
                                 oldMethod = newMethod;
                                 oldParams = newParams;

@@ -158,10 +168,15 @@
                         oldParams = newParams;
                     } else {
                         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;
                             }
                         } else if (useNew) {