Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java msg in console - Two methods with same method signature but not providing classes assignable?

Tags:

java

spring

While moving to java 1.8, I upgraded many dependencies in my project. It is application based on spring 4.3, with lot of external dependencies, for example: JMS, HTTP client, FTP, XMLs, etc.

When the application starts, I am now getting the following messages in the console:

Two methods with same method signature but not providing classes assignable? "public final int java.util.concurrent.ConcurrentHashMap$CollectionView.size()" and "public abstract int java.util.Set.size()" please report!

Any idea what this error message is and how to look for which jar caused the issue?

Also any way I can print some additional data on console about which class/thread/stack is printing this error.

like image 801
hemant1900 Avatar asked Oct 17 '22 19:10

hemant1900


1 Answers

I managed to look at the code a bit provided by the github link and figured out why you weren't getting a stack trace. It's not throwing an exception.

Source: https://github.com/jkuhnert/ognl/blob/master/src/java/ognl/OgnlRuntime.java

private static MatchingMethod findBestMethod(List methods, Class typeClass, String name, Class[] argClasses) {
    MatchingMethod mm = null;
    IllegalArgumentException failure = null;
    for (int i = 0, icount = methods.size(); i < icount; i++) {
        // ...

        if (mm == null || mm.score > score) {
            mm = new MatchingMethod(m, score, report, mParameterTypes);
            failure = null;
        } else if (mm.score == score) {
            if (Arrays.equals(mm.mMethod.getParameterTypes(), m.getParameterTypes()) && mm.mMethod.getName().equals(m.getName())) {
                if (mm.mMethod.getDeclaringClass().isAssignableFrom(m.getDeclaringClass())) {
                    if (!retsAreEqual && !mm.mMethod.getReturnType().isAssignableFrom(m.getReturnType()))
                        System.err.println("Two methods with same method signature but return types conflict? \""+mm.mMethod+"\" and \""+m+"\" please report!");

                    mm = new MatchingMethod(m, score, report, mParameterTypes);
                    failure = null;
                } else if (!m.getDeclaringClass().isAssignableFrom(mm.mMethod.getDeclaringClass())) {
                    // this should't happen
                    System.err.println("Two methods with same method signature but not providing classes assignable? \""+mm.mMethod+"\" and \""+m+"\" please report!");
                } else if (!retsAreEqual && !m.getReturnType().isAssignableFrom(mm.mMethod.getReturnType()))
                    System.err.println("Two methods with same method signature but return types conflict? \""+mm.mMethod+"\" and \""+m+"\" please report!");
            } else {
                // ... cut out
            }
        }
    }
    if (failure != null)
        throw failure;
    return mm;
}

I've cut out a bunch of code around it. Your code is failing at the place that literally has a comment that states this shouldn't happen.

Oops.

Anyways, it doesn't cause a failure as it doesn't actually assign anything to failure and it would have thrown an actual stacktrace had it failed somewhere else.

I have no idea why this statement is triggered, as I am not an expert on reflection.

!m.getDeclaringClass().isAssignableFrom(mm.mMethod.getDeclaringClass())

However, it simply steps over and continues executing through the for loop without adding an exception or doing anything else. I would assume it keeps whatever the first argument is and continues evaluating.

If you're still suspicious, use Maven to map a dependency tree to this library and see if there's an updated version that doesn't break things.

like image 135
Compass Avatar answered Oct 21 '22 08:10

Compass