Anyone have any advice on this one? ```java.lang.C...
# troubleshooting
r
Anyone have any advice on this one?
Copy code
java.lang.ClassCastException: org.codehaus.janino.CompilerFactory cannot be cast to org.codehaus.commons.compiler.ICompilerFactory
I have a job that using both the streaming and table APIs similar to the Immerok Table Deduplication example, however the job seems to fail once it starts actually doing anything Table API related. I have I believe all of the appropriate references and I’ve tried several attempts at explicitly removing the conflicting bits (as they would be included in the compiled jar already):
Copy code
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-api-java-bridge</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
        </dependency>
        <dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-planner-loader</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
    <exclusions>
        <exclusion>
            <artifactId>*</artifactId>
                <groupId>org.codehaus.janino</groupId>
            </exclusion>
        </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-runtime</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
    <exclusions>
        <exclusion>
            <artifactId>*</artifactId>
            <groupId>org.codehaus.janino</groupId>
        </exclusion>
    </exclusions>
</dependency>
I’ve tried several variations of this - any ideas would be welcome as it only seems to be a runtime issue (but I can’t reproduce it in an IDE).
m
Do you have Janino as a dependency?
I recall Flink requiring a specific version
r
Not explicitly anywhere, although there are quite a few Flink-related dependencies in this particular application. I’m assuming it’s a transitive dependency. All the scopes above default to compile in the IDE but are swapped to provided in the Dockerfile that handles running the jobs.
Hrm, it looks like the
flink-clients
dependency seems to bring in a
commons-cli:commons-cli
- maybe that’s related?
Not seeing anything that explicitly jumps out as the Janino one that’s being compiled in.
s
what about something like that
mvn dependency:tree | grep janino
?
r
I’ll try that in a second, just stepped away for a few. I’ll follow up when I know more, thanks!
So - not seeing any dependencies via the
dependency:tree
to Janino anywhere.
s
probably you need to check your jars to see which one contains janino it seems java somehow was able to find it based on the exception you've mentioned
r
I downloaded the jar for the application from blob storage to see what all was in there, I can confirm that I see several org.codehaus.janino packages in it:
I also see the org.codehaus.commons ones too:
But I’m not familiar enough with that’s going to to know if both of those should be excluded or just the janino one?
Looking at the External Libraries references in the Maven project, I do see two separate versions of those related libraries being referenced which may/may not be a problem:
s
yes, that might be the issue
r
All of the Flink jobs leverage a base pom file, so trying to see which specific dependencies are bringing in one version and which come from another when the jar is built.
And each individual job is a child from the base pom. Only the job that relies on the Table API appears to have this problem though.
s
or let's double check what is your Flink version?
r
It’s 1.15.2 for all of the jobs
(similar to the Immerok example in the original post)
s
well... for all Flink between 1.13 .x and 1.17.x there should be janino 3.0.11
for Flink 1.18.0 there should be 3.1.10
r
Interesting - so I’m wondering where these two 3.1.6 and 3.1.9 respective versions would be coming from.
s
that i can nott say in flink 1.15.x there is no such dependency
r
Both appear to be the commons-compiler, so it must be some non-Flink dependency
Specifically a non-Flink dependency with the compile scope that’s packaging this into the jar.
Although I suppose I could add this as an exclude in the artifact set for the maven-shade-plugin for this particular job as well. I’d imagine that would work?
Similar to what is done with things like these:
Copy code
<artifactSet>
    <excludes>
        <exclude>org.apache.flink:flink-shaded-force-shading</exclude>
        <exclude>com.google.code.findbugs:jsr305</exclude>
        <exclude>org.slf4j:*</exclude>
        <exclude>org.apache.logging.log4j:*</exclude>
    </excludes>
</artifactSet>
s
that i can not say because from one side it could help to get the right janino dependency for Flink however at the same time it could break something else if in your project this dependency is required
r
I attempted to shade the jar similar to the above shading out
org.codehaus.*
however ended up getting the same exception.
Additionally I verified that the following dependencies are not present/included within this particular. These are both brought in in other modules, none of which are referenced by this specific Flink job/pom:
The larger stacktrace looks like:
Copy code
Application failed unexpectedly: java.util.concurrent.CompletionException: org.apache.flink.client.deployment.application.ApplicationExecutionException: Could not execute application.
	at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292) ~[?:1.8.0_345]
	at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308) ~[?:1.8.0_345]
	at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:957) ~[?:1.8.0_345]
	at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:940) ~[?:1.8.0_345]
	at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488) ~[?:1.8.0_345]
	at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1990) ~[?:1.8.0_345] 
...
Caused by: org.apache.flink.client.program.ProgramInvocationException: The main method caused an error: Unable to instantiate java compiler
	at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:372) ~[flink-dist-1.15.2-stream3.jar:1.15.2-stream3]
...
Caused by: java.lang.IllegalStateException: Unable to instantiate java compiler
	at org.apache.calcite.rel.metadata.JaninoRelMetadataProvider.compile(JaninoRelMetadataProvider.java:428) ~[?:?]
...
Caused by: java.lang.ClassCastException: org.codehaus.janino.CompilerFactory cannot be cast to org.codehaus.commons.compiler.ICompilerFactory
	at org.codehaus.commons.compiler.CompilerFactoryFactory.getCompilerFactory(CompilerFactoryFactory.java:129) ~[flink-table-runtime-1.15.2-stream3.jar:1.15.2-stream3]
...
which sounds like more of a missing dependency problem
m
Do you have additional libraries in your lib folder?
r
The only one per the docker file that’s being added is one related to logging (specifically log4j templating):
Copy code
/flink/lib/log4j-layout-template-json-2.17.1.jar
I was assuming based on the Immerok example POM that the only dependencies I needed related to table api were the ones defined in there (all of which are present). Is it possible there’s some additional ones that I might need?
As far as dependencies in this particular troublesome job, there’s:
Copy code
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-streaming-java</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-clients</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-api-java-bridge</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-planner-loader</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-runtime</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-connector-kafka</artifactId>
    <version>${flink.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-connector-base</artifactId>
    <version>${flink.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-json</artifactId>
    <version>${flink.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-connector-elasticsearch7</artifactId>
    <version>${flink.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-avro-confluent-registry</artifactId>
    <version>${flink.version}</version>
</dependency>
m
I need to defer until I’m behind a laptop
👍 1
r
All of which use compile scope within the IDE which is adjusted to provided in the Dockerfile via a:
Copy code
mvn -T 1C -e install -Dflink.scope=provided -B
Just following up on this again. Still experiencing the same issue as prior and I believe it’s likely related to some of the dependencies either not being explicitly compiled or too many conflicting ones in the same jar that’s being executed. Image-wise, we’re using the Flink image from Ververica Platform (in the process of migrating to the operator soon), which should be specifically the
1.15.2-stream3-scala_2.12-java8
image, which has previously worked as expected however the project was recently moved to a different directory with a parent pom and cleaned up, the only major changes were migrating from the following dependencies:
Copy code
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-java</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-streaming-java</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-clients</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-api-java-bridge</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-planner_${scala.binary.version}</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-streaming-scala_${scala.binary.version}</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
to the dependencies that were shared above (non explicit Scala versioned ones). I’m unsure if some of the newer ones need to be explicitly declared as compile scope or if there’s another issue at play.
Ugh, I just realized the older project was explicitly being compiled against 1.8 and the new project targets 11. Which would make sense as to why the issue would be compiler-specific, going to try bumping the image to use the java11 one instead of the java8 one.
Attempted running the job against the Java11 image and it had the same exception with slightly more detail:
Copy code
Caused by: java.lang.ClassCastException: class org.codehaus.janino.CompilerFactory cannot be cast to class org.codehaus.commons.compiler.ICompilerFactory (org.codehaus.janino.CompilerFactory is in unnamed module of loader org.apache.flink.util.ChildFirstClassLoader @6dab9b6d; org.codehaus.commons.compiler.ICompilerFactory is in unnamed module of loader 'app')
s
do i understand correctly that with jdk 8 it works without issues?
r
Prior to migrating to this new directory (with a parent POM etc.), it ran with the following dependendencies targeting the java8 image:
Copy code
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-java</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-streaming-java</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-clients</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-api-java-bridge</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-planner_${scala.binary.version}</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-streaming-scala_${scala.binary.version}</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
And it was explicitly targeting 1.8 in the `maven-compiler-plugin`:
Copy code
<configuration>
    <source>${target.java.version}</source>
    <target>${target.java.version}</target>
</configuration>
The above worked originally, however after migrating the project over to use the parent POM I haven’t been able to get it to work targeting 11. I’ve updated the Flink image to use the
-java11
variant instead of the
-java8
one, updated all of the dependencies to match those defined earlier and in the Immerok Table API example, but have continually fought this error on any attempts to run against 11.
s
Copy code
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-planner_${scala.binary.version}</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
this module should bring the correct janino dependency
if i understand correctly your poms this is removed from the final version
then at least the correct janino dependency shold be specified, may be something else, that i don't know
r
Okay, perhaps that’s the issue. When targeting 11 does the newer
flink-table-planner-loader
one bring in janino as well? If so maybe that’s the issue and it should be explicitly compile scoped (as
flink.scope
is replaced during the build to provided)
So I tried reverting back to the older dependencies and targeting 1.8 and got a few errors related to the planner, namely:
Copy code
Caused by: org.apache.flink.client.program.ProgramInvocationException: The main method caused an error: Could not instantiate the executor. Make sure a planner module is on the classpath
...
Caused by: org.apache.flink.table.api.ValidationException: Multiple factories for identifier 'default' that implement 'org.apache.flink.table.delegation.ExecutorFactory' found in the classpath.

Ambiguous factory classes are:

org.apache.flink.table.planner.delegation.DefaultExecutorFactory
org.apache.flink.table.planner.loader.DelegateExecutorFactory
These are the dependencies that job was using:
Copy code
<dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-streaming-java</artifactId>
            <version>${flink.version}</version>
            <scope>${flink.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-java</artifactId>
            <version>${flink.version}</version>
            <scope>${flink.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-clients</artifactId>
            <version>${flink.version}</version>
            <scope>${flink.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-table-api-java-bridge</artifactId>
            <version>${flink.version}</version>
            <scope>${flink.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.flink</groupId>
            <artifactId>flink-table-planner_2.12</artifactId>
            <version>${flink.version}</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.flink</groupId>
                    <artifactId>flink-table-runtime</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.flink</groupId>
                    <artifactId>flink-scala_2.12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
I had to do some exclusions due to the maven-enforce plugin that was catching multiple dependencies
So it doesn’t seem to work with the dependencies that it did prior (maven-enforce picks out duplicate classes from the planner dependency) and the latter (Immerok example) results in the unable to instantiate java compiler error.
Still continuing to troubleshoot this and I managed to remove any additional Flink dependencies in the parent POM, so the only Flink dependencies that I can see are the following:
Copy code
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-streaming-java</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-clients</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-api-java-bridge</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-planner-loader</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-table-runtime</artifactId>
    <version>${flink.version}</version>
    <scope>${flink.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-connector-kafka</artifactId>
    <version>${flink.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-connector-base</artifactId>
    <version>${flink.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-json</artifactId>
    <version>${flink.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-connector-elasticsearch7</artifactId>
    <version>${flink.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-avro-confluent-registry</artifactId>
    <version>${flink.version}</version>
</dependency>
And all of the instances of
flink.scope
are replaced with
provided
when building the jars (they use
compile
for running/testing in the IDE). As mentioned before the image being used behind the scenes would be Ververica Platform’s v2.8 (
1.15.2-stream4-scala_2.12-java8
). But based on the error message that I’m seeing in the logs, it looks like it’s referencing the table-api-uber jar behind the scenes:
Copy code
Caused by: java.lang.ClassCastException: org.codehaus.janino.CompilerFactory cannot be cast to org.codehaus.commons.compiler.ICompilerFactory
	at org.codehaus.commons.compiler.CompilerFactoryFactory.getCompilerFactory(CompilerFactoryFactory.java:129) ~[flink-table-runtime-1.15.2-stream3.jar:1.15.2-stream3]
	at org.codehaus.commons.compiler.CompilerFactoryFactory.getDefaultCompilerFactory(CompilerFactoryFactory.java:79) ~[flink-table-runtime-1.15.2-stream3.jar:1.15.2-stream3]
...
[flink-table-api-java-uber-1.15.2-stream3.jar:1.15.2-stream3]
However, since all of my Flink-related dependencies use provided, I’m not entirely sure how I’d be getting a conflict.
s
that's probably i can't help since i've never used used Ververica platform.... 🤔
r
Yeah, I’m not terribly crazy about it, but as far as I’m aware, it’s using the above image
1.15.2-stream4-scala_2.12-java8
and the confusing part is - all of this worked prior to migrating the project over to a separate directory. The only major change was everything in the previous one targeted 1.8 (although still worked against the same image), never previously encountered any of the Janino issues.
The
org.codehaus.janino.CompilerFactory cannot be cast to org.codehaus.commons.compiler.ICompilerFactory
certainly makes it seem as though an extra dependency is in there that shouldn’t be though.
s
Don't you consider using new 1.18 Flink? In that version the janitor dependency was upgraded till the latest 3.1.10? Also somewhere in the past there were some complaints in mailing list that old janino 3.0.x doesn't support jdk 11 well enough
r
We’re currently a bit locked into Ververica Platform although they recently changed their “forever” support for their free version, which has us pinned to 1.15.x at the moment. Planning to migrate to the official Flink Operator hopefully in the next month or so, but trying to consolidate all of the jobs right now (thus this migration effort). I’m just perplexed as to why essentially the same job with no dependency changes and targeting the same image is encountering these Janino errors. Issue can’t easily be reproduced out of an IDE either as the job runs without issue in IntelliJ.
@Sergey Nuyanzin / @Martijn Visser After fighting with this for too many days, I eventually added the following configuration in as a last ditch effort and it appeared to work after stumbling upon it via the docs and archived mailing list:
Copy code
classloader.resolve-order: parent-first
Just wanted to close the loop here, thanks to you both for helping fight this.
👍 2