Skip to content

fix: handling empty yaml config file with a comment only#3301

Open
csviri wants to merge 6 commits intooperator-framework:mainfrom
csviri:improve-yaml-comment
Open

fix: handling empty yaml config file with a comment only#3301
csviri wants to merge 6 commits intooperator-framework:mainfrom
csviri:improve-yaml-comment

Conversation

@csviri
Copy link
Copy Markdown
Collaborator

@csviri csviri commented Apr 20, 2026

Signed-off-by: Attila Mészáros a_meszaros@apple.com

Copilot AI review requested due to automatic review settings April 20, 2026 09:59
@openshift-ci openshift-ci Bot requested review from metacosm and xstefank April 20, 2026 09:59
@csviri csviri changed the title fix handling empty yaml config file with a comment only fix: handling empty yaml config file with a comment only Apr 20, 2026
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves YamlConfigProvider behavior when the YAML config file is effectively empty (empty content or comment-only), and adds regression tests to cover those cases.

Changes:

  • Add tests asserting empty/comment-only YAML files produce no config values.
  • Adjust YAML loading to return an empty config map when Jackson reports empty input.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
operator-framework/src/test/java/io/javaoperatorsdk/operator/config/loader/provider/YamlConfigProviderTest.java Adds coverage for empty and comment-only YAML config files.
operator-framework/src/main/java/io/javaoperatorsdk/operator/config/loader/provider/YamlConfigProvider.java Adds handling for Jackson “no content” parsing cases by returning an empty map.

Comment on lines +106 to +108
} catch (com.fasterxml.jackson.databind.exc.MismatchedInputException e) {
log.warn("{} contains no configuration data", path);
return Map.of();
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching MismatchedInputException broadly will also swallow real YAML/type errors (e.g., a top-level YAML sequence instead of a mapping) and treat them as "no configuration data", changing prior behavior where such cases failed fast. Please narrow this handling to the true empty/comment-only case (e.g., detect empty content via a JsonParser and nextToken()==null, or otherwise check for the specific "no content" condition) so malformed/non-map configs still surface as errors.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this comment. You cannot be sure the file is empty.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, improved this.

Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Comment on lines +106 to +108
} catch (com.fasterxml.jackson.databind.exc.MismatchedInputException e) {
log.warn("{} contains no configuration data", path);
return Map.of();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this comment. You cannot be sure the file is empty.

csviri added 2 commits April 21, 2026 14:41
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

csviri and others added 2 commits April 21, 2026 16:20
…onfig/loader/provider/YamlConfigProviderTest.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…onfig/loader/provider/YamlConfigProvider.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants