What Should I Do if ClassCastException Is Reported Due to Flink JAR Package Conflicts?
Symptom
An error is reported when a job is started after introducing a third-party dependency package to Flink lib.
ClassCastException: X Cannot be cast to X
Cause Analysis
The introduced third-party dependency package conflicts with the dependency package in Flink. Precisely, the classes in the third-party dependency package are incompatible, resulting in failure to instantiate certain functions.
Solution
Method 1: Remove the conflict packages from the introduced third-party JAR. This method is recommended.
Method 2: Set classloader.resolve-order to parent-first in the flink-conf.yaml configuration file. Modify Flink class loading sequence so that the dependency packages provided by Flink are preferentially loaded.