java.util.ServiceConfigurationError: com.fasterxml.jackson.databind.Module: Provider com.fasterxml.jackson.module.scala.DefaultScalaModule could not be instantiated
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:582)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:804)
at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:722)
at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1395)
at com.fasterxml.jackson.databind.ObjectMapper.findModules(ObjectMapper.java:1131)
at org.apache.beam.sdk.testing.TestPipeline.<clinit>(TestPipeline.java:253)
. . .
Caused by: java.lang.NoClassDefFoundError: scala/collection/GenMap
at com.fasterxml.jackson.module.scala.modifiers.ScalaTypeModifier.<init>(ScalaTypeModifier.scala:15)
at com.fasterxml.jackson.module.scala.modifiers.ScalaTypeModifierModule.$init$(ScalaTypeModifier.scala:54)
at com.fasterxml.jackson.module.scala.DefaultScalaModule.<init>(DefaultScalaModule.scala:18)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:780)
... 61 more
Nowhere in our code do we directly call GenMap
but it seems to be a side effect of calling jackson
in our tests.
The error happens at
public final transient TestPipeline pipeline = TestPipeline.create();
specifically org.apache.beam.sdk.testing.TestPipeline
in
@RunWith(JUnit4.class)
public class BeamUtilsTest {
private static final Logger logger = LoggerFactory.getLogger(BeamUtilsTest.class);
@Rule
public final transient TestPipeline pipeline = TestPipeline.create();
@Test
public void testJoins() throws Exception {
Map<String, PCollection<JsonNode>> map = new HashMap<>();
map.put("users", pipeline.apply("readUsers",
BeamUtils.readJSONFile(pathOfResource("join-data/users.jsonl"))));
map.put("accounts", pipeline.apply("readAccounts",
BeamUtils.readJSONFile(
pathOfResource("join-data/accounts.jsonl"))));
JsonNode joinExpression = JsonFile.read(pathOfResource("join-data/usersAccounts.json"));
PCollection<JsonNode> joinedCollection = BeamUtils.join(map, JsonBuilder.newBuilder().set("/withJoin",joinExpression).build());
Map<String, String> validationMap = new HashMap<>();
validationMap.put("mickey.mouse", "AD01");
validationMap.put("minni.mouse", "AD05");
validationMap.put("donald.duck", "AD06");
PAssert.that("Join fields should exist", joinedCollection)
.satisfies((SerializableFunction<Iterable<JsonNode>, Void>) jsonNodeIterable -> {
jsonNodeIterable.forEach(jsonNode -> {
logger.info(jsonNode.toPrettyString());
if (!jsonNode.path("userId").isMissingNode()) {
String userId = jsonNode.path("userId").textValue();
assert !validationMap.containsKey(userId) || jsonNode.path("accountId").textValue() != null;
}
});
return (Void) null;
});
pipeline.run();
}
Context
I am trying to upgrade our project from Java 8 and older to Java 11 and 17, where most of my time has been spent in dependency hell, especially dealing with the various base version of Scala, old Apache Spark code, and other things.
This is simply the latest problem I am trying to resolve, but I have been fighting it for so long, I am not clear on backing out of the problem.
The test context is various services running under Docker. While I have some experience with Beam, and using dealing with JSON in Beam, I did not write this test, and I am a little mystified why jackson
needs Scala libraries.
At this point, I would appreciate some insights as I am getting a little brain-dead working on this issue, and losing my ability to think creatively.
I noticed that scala.collection.GenMap
was removed in newer versions of Scala, so this may also be a contributing factor. Adding
testImplementation 'org.scala-lang:scala-library:2.12.9' // scala.collection.GenMap
. . .
testFixturesImplementation 'org.scala-lang:scala-library:2.12.9' // scala.collection.GenMap
to our build.gradle file does not seem to help.