Domanda

Hi I try to migrate project to java 7 (JDK1.7.0_21) from java 6. On one test I noticed failures.

Update: I debugged the problem. I got to ReflectiveTypeFinder.findExpectedType.

public Class<?> findExpectedType(Class<?> fromClass) {
for (Class<?> c = fromClass; c != Object.class; c = c.getSuperclass()) {
    for (Method method : c.getDeclaredMethods()) {
        if (canObtainExpectedTypeFrom(method)) {
            return expectedTypeFrom(method);
        }
    }
}
throw new Error("Cannot determine correct type for " + methodName + "() method.");

}

Between JDK6 and JDK7 is different order got from c.getDeclaredMethods(). I checked on fly on both versions both methods would pass the condition so matters only which method will be first on the list.

Updated question is: Does hamcrest method should check something more or my class which is extending CustomTypeSafeMatcher is badly written?

My MyMatchedObjectMatcher has two matchesSafely methods:

@Override
protected boolean matchesSafely(MyMatchedObject actualObject) {(...)}

and

protected boolean matchesSafely(List<MyMatchedObject> actualObjectList) {(...)}

The nearest reported issue I founded is: https://github.com/hamcrest/JavaHamcrest/issues/30 . But due to unexpected behavior of internal java method I think that it could be not Hamcrest problem..

Used Hamcrest 1.3

È stato utile?

Soluzione

My college from my company solved this problem.

The convention in hamcrest is to have one matching method. But it could be better written, ex. checking if method has override annotation.

Solution for me was to delete second method (could be also renamed). On JDK6 it worked by luck ;).

PS: Thanks you Joe for stimulation.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top