reta commented on code in PR #1784: URL: https://github.com/apache/cxf/pull/1784#discussion_r1554575151
########## rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/Beanspector.java: ########## @@ -58,49 +60,63 @@ public Beanspector(T tobj) { init(); } - @SuppressWarnings("unchecked") - private void init() { - if (tclass == null) { - tclass = (Class<T>)tobj.getClass(); - } - for (Method m : tclass.getMethods()) { - if (isGetter(m)) { - String pname = getPropertyName(m); - if (!getters.containsKey(pname)) { - getters.put(getPropertyName(m), m); - } else { - // Prefer the getter that has the most specialized class as a return type - Method met = getters.get(pname); - if (met.getReturnType().isAssignableFrom(m.getReturnType())) { - getters.put(pname, m); - } - } - } else if (isSetter(m)) { - String pname = getPropertyName(m); - if (!setters.containsKey(pname)) { - setters.put(getPropertyName(m), m); - } else { - // Prefer the setter that has the most specialized class as a parameter - Method met = setters.get(pname); - if (met.getParameterTypes()[0].isAssignableFrom(m.getParameterTypes()[0])) { - setters.put(pname, m); - } - } - } - } - // check type equality for getter-setter pairs - Set<String> pairs = new HashSet<>(getters.keySet()); - pairs.retainAll(setters.keySet()); - for (String accessor : pairs) { - Class<?> getterClass = getters.get(accessor).getReturnType(); - Class<?> setterClass = setters.get(accessor).getParameterTypes()[0]; - if (!setterClass.isAssignableFrom(getterClass)) { - throw new IllegalArgumentException(String - .format("Accessor '%s' type mismatch, getter type is %s while setter type is %s", - accessor, getterClass.getName(), setterClass.getName())); - } - } - } + @SuppressWarnings("unchecked") + private void init() { + if (tclass == null) { + tclass = (Class<T>)tobj.getClass(); + } + + List<Method> methods = Arrays.asList(tclass.getMethods()); + Collections.sort(methods, (m1, m2) -> { + if (m1.getDeclaringClass().equals(m2.getDeclaringClass())) { + return 0; + } else if (m1.getDeclaringClass().equals(tclass)) { + return -1; + } else { + return 1; + } + }); + + for (Method m : methods) { + if (isGetter(m)) { + String pname = getPropertyName(m); + if (!getters.containsKey(pname)) { + getters.put(getPropertyName(m), m); + } else { + // Prefer the getter that has the most specialized class as a return type + Method met = getters.get(pname); + if (met.getReturnType().isAssignableFrom(m.getReturnType())) { + getters.put(pname, m); + } + } + } else if (isSetter(m)) { + String pname = getPropertyName(m); + System.out.println(m); Review Comment: Debug leftovers? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@cxf.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org