apache/flink · error · RuntimeException
ComparatorFactory has not been initialized from configuratio
Error message
ComparatorFactory has not been initialized from configuration.
What it means
RuntimeComparatorFactory.createComparator throws this when its comparator field is null, i.e. the factory was asked to produce a comparator before readParametersFromConfig successfully populated it. It is a lifecycle misuse: the factory is designed to be written to config on the client and re-initialized from config on the cluster, never used directly after bare construction.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/RuntimeComparatorFactory.java:72
public void readParametersFromConfig(Configuration config, ClassLoader cl)
throws ClassNotFoundException {
try {
comparator =
(TypeComparator<T>)
InstantiationUtil.readObjectFromConfig(config, CONFIG_KEY, cl);
} catch (ClassNotFoundException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Could not serialize serializer into the configuration.", e);
}
}
@Override
public TypeComparator<T> createComparator() {
if (comparator != null) {
return comparator;
} else {
throw new RuntimeException(
"ComparatorFactory has not been initialized from configuration.");
}
}
}
View on GitHub (pinned to 2f3c205e92)
Solutions
- Always run the full lifecycle: writeParametersToConfig(config) on the sender, readParametersFromConfig(config, cl) on the receiver, then createComparator().
- In tests, round-trip the factory through a Configuration and InstantiationUtil to reproduce production behavior instead of calling createComparator on a fresh instance.
- If readParametersFromConfig can fail, fail fast and do not call createComparator; propagate the earlier error instead of masking it with this one.
Example fix
// before RuntimeComparatorFactory<MyType> f = new RuntimeComparatorFactory<>(myComparator); TypeComparator<MyType> c = f.createComparator(); // if comparator was never set/read -> boom // after Configuration cfg = new Configuration(); new RuntimeComparatorFactory<>(myComparator).writeParametersToConfig(cfg); RuntimeComparatorFactory<MyType> f2 = new RuntimeComparatorFactory<>(); f2.readParametersFromConfig(cfg, getClass().getClassLoader()); TypeComparator<MyType> c = f2.createComparator();
Defensive patterns
Strategy: validation
Validate before calling
public static RuntimeComparatorFactory<T> roundTrip<T>(
RuntimeComparatorFactory<T> src, Configuration cfg, ClassLoader cl)
throws ClassNotFoundException {
src.writeParametersToConfig(cfg);
RuntimeComparatorFactory<T> out = new RuntimeComparatorFactory<>();
out.readParametersFromConfig(cfg, cl);
return out; // only call createComparator() on the returned, initialized factory
} Prevention
- Treat ComparatorFactory as write->read->create lifecycle; never call createComparator on an uninitialized instance.
- Abort the operator setup if readParametersFromConfig throws; do not continue to createComparator.
- In tests, always round-trip through a Configuration instead of direct construction.
When it happens
Trigger: Constructing RuntimeComparatorFactory (no-arg or with a comparator) and calling createComparator() without a preceding successful readParametersFromConfig; or readParametersFromConfig failing early (null config/classloader throws NPE, or deserialization error) and createComparator being called anyway.
Common situations: Unit tests that instantiate the factory directly instead of round-tripping through Configuration. Framework code paths that reuse a factory instance after a failed config read. Copy-paste integration code that skips the write/read config round trip.
Related errors
- SerializerFactory has not been initialized from configuratio
- The program's entry point class '{className}' threw an error
- The program's entry point class '{className}' caused an exce
- Failed to create reader
- Failed to open the GeneratorFunction
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/4997d253c7e504dc.
Report an issue: GitHub.