Treat `master_key_ed25519` as optional as it is supposed to be
Running the bw file related test gives us right now the following exception, twice:
[junit] java.util.NoSuchElementException: No value present
[junit] at java.base/java.util.Optional.get(Optional.java:143)
[junit] at org.torproject.metrics.descriptorparser.parsers.BandwidthParser.addRelayLines(BandwidthParser.java:189)
[junit] at org.torproject.metrics.descriptorparser.parsers.BandwidthParser.run(BandwidthParser.java:170)
[junit] at org.torproject.metrics.descriptorparser.parsers.BandwidthParserTest.testBandwidthParserDbUploader(BandwidthParserTest.java:28)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[junit] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[junit] at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
[junit] at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
[junit] at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
[junit] at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
[junit] at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
[junit] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
[junit] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
[junit] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
[junit] at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
[junit] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
[junit] at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
[junit] at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:38)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:535)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1197)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:1042)
which makes me a bit nervous. I could not figure out so far where this is coming from, but it goes away if I address the root cause, so yay!
Here is the problem:
+ "\n" + relayLine.masterKeyEd25519().get()
This is assuming that the Ed25519 key is always available. However, it's actually optional:
/**
* Relays's master Ed25519 key, base64 encoded, without trailing "="s.
*
* @since 2.6.0
*/
Optional<String> masterKeyEd25519();
And we actually do the right thing later one with:
String masterKey = "";
if (relayLine.masterKeyEd25519().isPresent()) {
masterKey = relayLine.masterKeyEd25519().get();
}
What we actually should do is doing the isPresent()
check first and then use the resulting masterKey
for both cases.