Skip to content

Fix MultiSourceReader compatibility with Java 16+ #3670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

gummybug
Copy link

@gummybug gummybug commented Jul 22, 2024

This is a fix for #2709

LineNumberReader was updated in Java 16 to consider EOS a line terminator, so if a source doesn't end in newline, getLineNumber() will return 1 + the value in older Java versions. We ran into this issue at Airbnb where we use MultiSourceReader to read graphqls files. If a schema file didn't end in newline, the SourceLocation for some types would be incorrect. This PR attempts to address this issue.

Testing:
I ran the unit tests with Java 11 and Java 20 (this required bumping the language version in build.gradle) with and without this fix. Without this fix, LineNumberingTest, MultiSourceReaderTest, ParserExceptionTest, TypeDefinitionRegistryTest fail with Java 20 as described in the open issue. With this fix, they succeed.
This also fixed the bug we ran into at Airbnb.

}
LINE_NUMBER_READER_EOS_IS_TERMINATOR = reader.getLineNumber() > 0;
}

Copy link
Member

Choose a reason for hiding this comment

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

Clever!

@bbakerman bbakerman added this to the 22.2: non-breaking changes milestone Jul 23, 2024
Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution

throw new UncheckedIOException(e);
}
LINE_NUMBER_READER_EOS_IS_TERMINATOR = reader.getLineNumber() > 0;
}
Copy link
Member

Choose a reason for hiding this comment

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

Minor pick - I would encapsulate this into a static method

So you can do

private static final boolean LINE_NUMBER_READER_EOS_IS_TERMINATOR = determineStuff();

@bbakerman bbakerman added this pull request to the merge queue Jul 23, 2024
Merged via the queue into graphql-java:master with commit e933832 Jul 23, 2024
1 check passed
@dondonz
Copy link
Member

dondonz commented Jul 23, 2024

Thanks for this PR!

Leaving a link for later, this issue was reported a while back #2709 with a related suggestion to run tests on different Java versions to catch these issues earlier #2789. Might be time to look into different Java versions for our tests again. Thanks!

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