Commit 9ccb934f authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Avoid invoking overridable methods from constructors.

Fixes #33205.
parent 6408bd9a
# Changes in version 2.1?.? - 2020-0?-??
* Minor changes
- Avoid invoking overridable methods from constructors.
# Changes in version 2.10.0 - 2020-01-15
......
......@@ -22,8 +22,8 @@ public class BridgeNetworkStatusImpl extends NetworkStatusImpl
protected BridgeNetworkStatusImpl(byte[] rawDescriptorBytes,
int[] offsetAndLength, File descriptorFile, String fileName)
throws DescriptorParseException {
super(rawDescriptorBytes, offsetAndLength, descriptorFile,
false, false);
super(rawDescriptorBytes, offsetAndLength, descriptorFile, false);
this.splitAndParseParts(false);
this.setPublishedMillisFromFileName(fileName);
}
......
......@@ -26,14 +26,13 @@ public abstract class NetworkStatusImpl extends DescriptorImpl {
protected Map<Integer, String> flagStrings = new HashMap<>();
protected NetworkStatusImpl(byte[] rawDescriptorBytes, int[] offsetAndLength,
File descriptorFile, boolean containsDirSourceEntries,
boolean blankLinesAllowed) throws DescriptorParseException {
File descriptorFile, boolean blankLinesAllowed)
throws DescriptorParseException {
super(rawDescriptorBytes, offsetAndLength, descriptorFile,
blankLinesAllowed);
this.splitAndParseParts(containsDirSourceEntries);
}
private void splitAndParseParts(boolean containsDirSourceEntries)
protected final void splitAndParseParts(boolean containsDirSourceEntries)
throws DescriptorParseException {
int firstRIndex = this.findFirstIndexOfKey(Key.R);
int firstDirectorySignatureIndex = this.findFirstIndexOfKey(
......
......@@ -25,7 +25,8 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
protected RelayNetworkStatusConsensusImpl(byte[] consensusBytes,
int[] offsetAndLimit, File descriptorFile)
throws DescriptorParseException {
super(consensusBytes, offsetAndLimit, descriptorFile, true, false);
super(consensusBytes, offsetAndLimit, descriptorFile, false);
this.splitAndParseParts(true);
Set<Key> exactlyOnceKeys = EnumSet.of(
Key.VOTE_STATUS, Key.CONSENSUS_METHOD, Key.VALID_AFTER, Key.FRESH_UNTIL,
Key.VALID_UNTIL, Key.VOTING_DELAY, Key.KNOWN_FLAGS);
......
......@@ -21,7 +21,8 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
protected RelayNetworkStatusImpl(byte[] statusBytes, int[] offsetAndLength,
File descriptorFile) throws DescriptorParseException {
super(statusBytes, offsetAndLength, descriptorFile, false, true);
super(statusBytes, offsetAndLength, descriptorFile, true);
this.splitAndParseParts(false);
Set<Key> exactlyOnceKeys = EnumSet.of(
Key.NETWORK_STATUS_VERSION, Key.DIR_SOURCE, Key.FINGERPRINT,
Key.CONTACT, Key.DIR_SIGNING_KEY, Key.PUBLISHED);
......
......@@ -26,7 +26,8 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
protected RelayNetworkStatusVoteImpl(byte[] voteBytes, int[] offsetAndLength,
File descriptorFile)
throws DescriptorParseException {
super(voteBytes, offsetAndLength, descriptorFile, false, false);
super(voteBytes, offsetAndLength, descriptorFile, false);
this.splitAndParseParts(false);
Set<Key> exactlyOnceKeys = EnumSet.of(
Key.VOTE_STATUS, Key.PUBLISHED, Key.VALID_AFTER, Key.FRESH_UNTIL,
Key.VALID_UNTIL, Key.VOTING_DELAY, Key.KNOWN_FLAGS, Key.DIR_SOURCE,
......@@ -52,20 +53,6 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
protected void parseHeader(int offset, int length)
throws DescriptorParseException {
/* Initialize flag-thresholds values here for the case that the vote
* doesn't contain those values. Initializing them in the constructor
* or when declaring variables wouldn't work, because those parts are
* evaluated later and would overwrite everything we parse here. */
this.stableUptime = -1L;
this.stableMtbf = -1L;
this.fastBandwidth = -1L;
this.guardWfu = -1.0;
this.guardTk = -1L;
this.guardBandwidthIncludingExits = -1L;
this.guardBandwidthExcludingExits = -1L;
this.enoughMtbfInfo = -1;
this.ignoringAdvertisedBws = -1;
Scanner scanner = this.newScanner(offset, length).useDelimiter(NL);
Key nextCrypto = Key.EMPTY;
StringBuilder crypto = null;
......@@ -847,63 +834,63 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
return new TreeSet<>(Arrays.asList(this.knownFlags));
}
private long stableUptime;
private long stableUptime = -1L;
@Override
public long getStableUptime() {
return this.stableUptime;
}
private long stableMtbf;
private long stableMtbf = -1L;
@Override
public long getStableMtbf() {
return this.stableMtbf;
}
private long fastBandwidth;
private long fastBandwidth = -1L;
@Override
public long getFastBandwidth() {
return this.fastBandwidth;
}
private double guardWfu;
private double guardWfu = -1.0;
@Override
public double getGuardWfu() {
return this.guardWfu;
}
private long guardTk;
private long guardTk = -1L;
@Override
public long getGuardTk() {
return this.guardTk;
}
private long guardBandwidthIncludingExits;
private long guardBandwidthIncludingExits = -1L;
@Override
public long getGuardBandwidthIncludingExits() {
return this.guardBandwidthIncludingExits;
}
private long guardBandwidthExcludingExits;
private long guardBandwidthExcludingExits = -1L;
@Override
public long getGuardBandwidthExcludingExits() {
return this.guardBandwidthExcludingExits;
}
private int enoughMtbfInfo;
private int enoughMtbfInfo = -1;
@Override
public int getEnoughMtbfInfo() {
return this.enoughMtbfInfo;
}
private int ignoringAdvertisedBws;
private int ignoringAdvertisedBws = -1;
@Override
public int getIgnoringAdvertisedBws() {
......
......@@ -721,6 +721,8 @@ public class RelayNetworkStatusVoteImplTest {
assertEquals(3, vote.getDirKeyCertificateVersion());
assertEquals("80550987E1D626E3EBA5E5E75A458DE0626D088C",
vote.getIdentity());
assertTrue(vote.isSharedRandParticipate());
assertEquals(8, vote.getSharedRandCurrentNumReveals());
assertEquals(1303882477000L, /* 2011-04-27 05:34:37 */
vote.getDirKeyPublishedMillis());
assertEquals(1335504877000L, /* 2012-04-27 05:34:37 */
......@@ -745,6 +747,8 @@ public class RelayNetworkStatusVoteImplTest {
+ "F3Yh\nrXVaaoP07r6Ta+s0g1Zijm3lms50Nk/4tV2p8Y63c3F4Q3DAnK40Oi"
+ "kfOIwEj+Ny\n+zBRQssP3hPhTPOj/A7o3mZZwtL6x1sxpeu/nME1l5E=\n"
+ "-----END SIGNATURE-----\n", signature.getSignature());
assertEquals(184320, vote.getGuardBandwidthExcludingExits());
assertEquals(1, vote.getEnoughMtbfInfo());
assertTrue(vote.getUnrecognizedLines().isEmpty());
}
......@@ -1548,6 +1552,15 @@ public class RelayNetworkStatusVoteImplTest {
+ "grwbnD6I40odtsdtWYxqs0DvPweCur6qG2Fo5p5ivS4= 8");
}
@Test
public void testSharedRandCurrentValueLineEmpty()
throws DescriptorParseException {
RelayNetworkStatusVote vote =
VoteBuilder.createWithSharedRandCurrentValueLine(null);
assertEquals(-1, vote.getSharedRandCurrentNumReveals());
assertNull(vote.getSharedRandCurrentValue());
}
@Test
public void testSharedRandCurrentNoNumReveals()
throws DescriptorParseException {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment