{"record":{"id":"05a22485ff1eb8bd","repo":"apache/flink","slug":"no-value-present","errorCode":null,"errorMessage":"No value present","messagePattern":"No value present","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/types/SerializableOptional.java","lineNumber":44,"sourceCode":"import java.util.Optional;\nimport java.util.function.Consumer;\nimport java.util.function.Function;\n\n/** Serializable {@link Optional}. */\npublic final class SerializableOptional<T extends Serializable> implements Serializable {\n    private static final long serialVersionUID = -3312769593551775940L;\n\n    private static final SerializableOptional<?> EMPTY = new SerializableOptional<>(null);\n\n    @Nullable private final T value;\n\n    private SerializableOptional(@Nullable T value) {\n        this.value = value;\n    }\n\n    public T get() {\n        if (value == null) {\n            throw new NoSuchElementException(\"No value present\");\n        }\n        return value;\n    }\n\n    public boolean isPresent() {\n        return value != null;\n    }\n\n    public void ifPresent(Consumer<? super T> consumer) {\n        if (value != null) {\n            consumer.accept(value);\n        }\n    }\n\n    public <R extends Serializable> SerializableOptional<R> map(\n            Function<? super T, ? extends R> mapper) {\n        if (value == null) {\n            return empty();","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/SerializableOptional.java#L26-L62","documentation":"SerializableOptional is a serializable mirror of java.util.Optional. get() on the empty instance (created via SerializableOptional.empty(), which stores a null value) throws NoSuchElementException, exactly like Optional.get(). isPresent() exists to check first; the error means the code assumed a value that was never present.","triggerScenarios":"Calling get() without a preceding isPresent() check on an optional returned empty — e.g. from empty(), fromNullable(null), or a deserialized optional whose source had no value.","commonSituations":"Function inputs that are legitimately absent (optional config/field) reaching code that unconditionally calls get(); deserializing across versions where a field became nullable; porting code from Optional where get() misuse is a known anti-pattern.","solutions":["Guard with isPresent() before get(), or use orElse/orElseGet for defaults","Fix the upstream contract if absence is unexpected: make the producer always supply a value","In tests, cover the empty path explicitly so absence stops being an afterthought"],"exampleFix":"// before\nT v = opt.get(); // NoSuchElementException when empty\n\n// after\nT v = opt.isPresent() ? opt.get() : defaultValue;\n// or: T v = opt.orElse(defaultValue);","handlingStrategy":"validation","validationCode":"if (!opt.isPresent()) {\n    return defaultValue; // or throw a domain-specific exception\n}\nT v = opt.get();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call get() without isPresent()","Prefer orElse/orElseGet","Test the empty path in unit tests"],"tags":["flink","optional","no-such-element","null-handling"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}