Skip to content
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

Issue #14625: fix inspection violation OptionalGetWithoutIsPresent JavaParserTest testSingleLineComment #14811

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ public void testAppendHiddenBlockCommentNodes() throws Exception {
.isEqualTo(1);
}

/**
* Temporary java doc.
*
* @noinspection OptionalGetWithoutIsPresent
* @noinspectionreason OptionalGetWithoutIsPresent - until issue #14625
*/
@Test
public void testAppendHiddenSingleLineCommentNodes() throws Exception {
final DetailAST root =
Expand All @@ -120,10 +114,10 @@ public void testAppendHiddenSingleLineCommentNodes() throws Exception {
final Optional<DetailAST> singleLineComment = TestUtil.findTokenInAstByPredicate(root,
ast -> ast.getType() == TokenTypes.SINGLE_LINE_COMMENT);
assertWithMessage("Single line comment should be present")
.that(singleLineComment.isPresent())
.isTrue();
.that(singleLineComment.isPresent())
.isTrue();

final DetailAST comment = singleLineComment.get();
Copy link
Member

Choose a reason for hiding this comment

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

Please just use Optional#orElseThrow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nrmancuso , orElseThrow requires a Supplier argument, only default constructor is compatible.
Without arg to Ctor, we get another inspection problem NewExceptionWithoutArguments

We have to set default to NullPointerException if we want to use this method.

Copy link
Contributor Author

@MANISH-K-07 MANISH-K-07 Apr 23, 2024

Choose a reason for hiding this comment

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

final DetailAST comment = singleLineComment.orElseThrow();

assertWithMessage("Unexpected line number")
.that(comment.getLineNo())
Expand Down