JOSM/Mapillary

Failing unit tests

Closed this issue ยท 10 comments

We have 19 unit tests failing:

https://josm.openstreetmap.de/jenkins/job/Java-EarlyAccess-JOSM-Plugins/79/jdk=JDK12/testReport/

All with the same stacktrace:

junit.framework.AssertionFailedError: modifiers
	at org.openstreetmap.josm.plugins.mapillary.utils.TestUtil.getAccessibleField(TestUtil.java:40)
	at org.openstreetmap.josm.plugins.mapillary.io.download.SequenceDownloadRunnableTest.setUp(SequenceDownloadRunnableTest.java:39)
	at org.openstreetmap.josm.testutils.JOSMTestRules$TimeoutThread.run(JOSMTestRules.java:700)

Thank you for reporting, this has to do with reflective access to private fields in unit tests. Probably something has been changed in Java 12 that does no longer allow certain access. I already saw a deprecation warning when compiling with Java 10 in that part of the code.

try {
Field result = clazz.getDeclaredField(fieldName);
result.setAccessible(true);
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
modifiers.setInt(result, modifiers.getInt(result) & ~Modifier.FINAL);
return result;
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
fail(e.getLocalizedMessage());
}
return null;

I will take a look and see what I can do.

Just for reference:
It seems like Java is now carrying out what they already warn about when compiling with Java 10:

> Task :test
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.openstreetmap.josm.plugins.mapillary.utils.TestUtil (file:/builds/JOSM/Mapillary/build/classes/java/test/) to field java.lang.reflect.Field.modifiers
WARNING: Please consider reporting this to the maintainers of org.openstreetmap.josm.plugins.mapillary.utils.TestUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
  ๐Ÿ Finished after 38.83 seconds.

(excerpt of https://gitlab.com/JOSM/Mapillary/-/jobs/101974395)

Can you please log the stacktrace instead of just displaying the localized message? We don't know what exact exception is raised.

I'm removing the whole method, so this won't be a problem anymore.

Yes, one has to do with WireMock, where I forgot to add a stub for a certain URL, that's easy to fix.

The other one looks to me as if the unit tests can't access resources for classes from the main source set, in this case an image located in src/main/resources/images. @don-vip : Is there something I can add to build.xml that adds src/main/resources/ to the test classpath?

I'll reopen this, until it's completely resolved.

I just have added a new property in build-common.xml

So now you simply need to add:

<property name="plugin.resources.dir" value="src/main/resources"/>

Thanks! I now pushed e2df796...5d8911c , which should fix the failing tests.