GeezerVison is showing github.com — Bug: duplicate --config key reported but value shown · Issue #1308 · junit-team/junit-framework
Bug: duplicate --config key reported but value shown #1308DescriptionOverview
I am using the platform-version 1.0.2. The bug happens when I use the ConsoleLauncher (from a gradle JavaExec Task, but I doubt that matters).
I accidentally provided twice the same key for --config as follows:
'--config', 'forgive=".*spec:ch.tutteli.atrium.api.cc.en_UK.Iterable.error cases."',
'--config', 'forgive=".*spec:ch.tutteli.atrium.api.cc.en_UK.Iterable.failing cases."',
The following Exception was thrown
Exception in thread "main" java.lang.IllegalStateException: Duplicate key .*spec:ch.tutteli.atrium.api.cc.en_UK.Iterable.*error
at java.util.stream.Collectors.lambda$throwingMerger$114(Collectors.java:133)
at java.util.HashMap.merge(HashMap.java:1245)
at java.util.stream.Collectors.lambda$toMap$172(Collectors.java:1320)
at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at org.junit.platform.console.options.AvailableOptions.toCommandLineOptions(AvailableOptions.java:237)
at org.junit.platform.console.options.JOptSimpleCommandLineOptionsParser.parse(JOptSimpleCommandLineOptionsParser.java:41)
at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:68)
at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:47)
at org.junit.platform.console.ConsoleLauncher.main(ConsoleLauncher.java:39)
The error as such is fine, but I would have expected it reports that forgive was duplicated. I am not entirely sure if this a junit5 bug or a JDK8 bug but I guess you will find out quickly. Activitysormuras commented on Feb 24, 2018 Can you please try version 1.1.0 please?
Tried it locally with "--config foo=bar --config foo=baz" and results in the expected exception message:
java.lang.IllegalStateException: Duplicate key foo (attempted merging values bar and baz)
at java.base/java.util.stream.Collectors.duplicateKeyException(Collectors.java:131)
at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1(Collectors.java:178)
at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1494)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:511)
at org.junit.platform.console.options.AvailableOptions.toCommandLineOptions(AvailableOptions.java:257)
at org.junit.platform.console.options.JOptSimpleCommandLineOptionsParser.parse(JOptSimpleCommandLineOptionsParser.java:41)
[...]
sormuras commented on Feb 24, 2018 Nevertheless, it should be an instance of JUnitException with a message of Error parsing command-line arguments and an atttached cause: java.lang.IllegalStateException: Duplicate key foo (attempted merging values bar and baz).
Addressing this in master. robstoll commented on Feb 25, 2018 Nope, looks still the same. You can reproduce it as follows:
- git clone https://github.com/robstoll/atrium.git
- open misc/atrium-bc-test/build.gradle
- add '--config', 'forgive=test', to line 69
- gr :atrium-bc-test:build
Following the Exception message I got:
Exception in thread "main" java.lang.IllegalStateException: Duplicate key .*spec:ch.tutteli.atrium.api.cc.de_CH.Iterable.*(error cases|failing cases|context empty collection).*
sormuras commented on Feb 26, 2018 Will try later. But reading the initial error message carefully, I guess the command line configuration you use in the Gradle script is not correct. Your value is interpreted as a key -- see the "missing" tail of your value after the first space character: .*spec:ch.tutteli.atrium.api.cc.de_CH.Iterable.*(error
Perhaps, you have wrap the value string into an extra "? robstoll commented on Feb 26, 2018 That's actually what I figured at the beginning. In the first output in the description of this task I wrapped it in " and that was actually the reason why my argument got chopped into two parts (see also gradle/gradle#4510).
See the output in my last comment #1308 (comment), the argument is not split up. The error message is wrong nonetheless. sormuras commented on Feb 26, 2018 It's a bug in Java 8. See https://bugs.openjdk.java.net/browse/JDK-8040892 for details. It was fixed in Java 9.
@junit-team/junit-lambda shall we roll our own toMap helper and always emit a helpful error message?
private Map<String, String> map(List<KeyValuePair> pairs) {
Map<String, String> map = new HashMap<>();
for (KeyValuePair pair : pairs) {
String key = pair.key;
if (map.containsKey(key)) {
Exception cause = new IllegalStateException("Duplicate key " + key + " in: " + pairs);
throw new JUnitException("Error parsing command-line arguments", cause);
}
map.put(key, pair.value);
}
return map;
}
robstoll commented on Feb 26, 2018 Fair enough, I had a quick glance a the source code of junit5 before I reported the issue and thought it could be a bug in JDK8. I keep the issue open as it seems you want to discuss a few things. Close the issue whenever you want, for me it is done. sbrannen commented on Feb 26, 2018
@junit-team/junit-lambda shall we roll our own toMap helper and always emit the a helpful error message?
SGTM added 2 commits that reference this issue on Feb 26, 2018This issue will close once commit 73a5926 is merged into the 'main' branch.73a5926 This issue will close once commit bcec6fa is merged into the 'main' branch.bcec6fa added a commit that references this issue on Feb 28, 2018This issue will close once commit b3cec57 is merged into the 'main' branch.b3cec57 locked as resolved and limited conversation to collaborators on May 6, 2026
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|