Skip to content

8357862: Java argument file is parsed unexpectedly with trailing comment #25589

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions src/java.base/share/native/libjli/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,20 @@ static char* nextToken(__ctx_args *pctx) {
continue;
}
pctx->state = IN_COMMENT;
// return non-zero length token, terminated the comment marker
if (nextc - anchor > 0) {
if (pctx->parts->size == 0) {
token = clone_substring(anchor, nextc - anchor);
} else {
JLI_List_addSubstring(pctx->parts, anchor, nextc - anchor);
token = JLI_List_combine(pctx->parts);
JLI_List_free(pctx->parts);
pctx->parts = JLI_List_new(4);
}
pctx->cptr = nextc + 1;
return token;
Comment on lines +267 to +276
Copy link
Member Author

@sormuras sormuras Jun 2, 2025

Choose a reason for hiding this comment

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

This code duplicates a large part of the block of the previous case. Perhaps an internal helper method could be extracted?

Copy link
Contributor

Choose a reason for hiding this comment

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

right I agree that if there is common code we should extract it in a helper method

Copy link
Member Author

Choose a reason for hiding this comment

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

Or the handling of # can be merged with the previous case ... somehow.

}
// anchor after hashtag character
anchor = nextc + 1;
break;
case '\\':
Expand Down
15 changes: 12 additions & 3 deletions test/jdk/tools/launcher/ArgFileSyntax.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -21,9 +21,9 @@
* questions.
*/

/**
/*
* @test
* @bug 8027634 8210810 8240629
* @bug 8027634 8210810 8240629 8357862
* @summary Verify syntax of argument file
* @build TestHelper
* @run main ArgFileSyntax
Expand Down Expand Up @@ -172,6 +172,15 @@ private void verifyOutput(List<String> args, TestResult tr) {
"-version",
"-Dcontinue.with.leadingws=Line1continue with \f<ff> and \t<tab>"
}
},
{ // multiple args in one line and comments without preceding whitespace
{ "-Xmx32m -XshowSettings#COMMENT 1",
"-version#COMMENT 2"
},
{ "-Xmx32m",
"-XshowSettings",
"-version"
}
}
};

Expand Down