mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 15:00:30 +01:00
Fix index out of bound issues
At Capabilities I got an exception after going back from a new dev branch to master and getting p2p network data from nodes still running on the dev branch as that newly added capability was outside of the existing scope. I found another potential issue with DaoPhase.Phase and added a check there as well.
This commit is contained in:
parent
257550ac81
commit
9ed109330a
2 changed files with 14 additions and 2 deletions
|
@ -96,7 +96,10 @@ public class Capabilities {
|
||||||
* @return a {@link Capabilities} object
|
* @return a {@link Capabilities} object
|
||||||
*/
|
*/
|
||||||
public static Capabilities fromIntList(List<Integer> capabilities) {
|
public static Capabilities fromIntList(List<Integer> capabilities) {
|
||||||
return new Capabilities(capabilities.stream().map(integer -> Capability.values()[integer]).collect(Collectors.toSet()));
|
return new Capabilities(capabilities.stream()
|
||||||
|
.filter(integer -> integer < Capability.values().length)
|
||||||
|
.map(integer -> Capability.values()[integer])
|
||||||
|
.collect(Collectors.toSet()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -26,6 +26,7 @@ import io.bisq.generated.protobuffer.PB;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ import javax.annotation.concurrent.Immutable;
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@Value
|
@Value
|
||||||
|
@Slf4j
|
||||||
public class DaoPhase implements PersistablePayload, ImmutableDaoStateModel {
|
public class DaoPhase implements PersistablePayload, ImmutableDaoStateModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,7 +79,14 @@ public class DaoPhase implements PersistablePayload, ImmutableDaoStateModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DaoPhase fromProto(PB.DaoPhase proto) {
|
public static DaoPhase fromProto(PB.DaoPhase proto) {
|
||||||
return new DaoPhase(Phase.values()[proto.getPhaseOrdinal()], proto.getDuration());
|
int ordinal = proto.getPhaseOrdinal();
|
||||||
|
if (ordinal >= Phase.values().length) {
|
||||||
|
log.warn("We tried to access a ordinal outside of the DaoPhase.Phase enum bounds and set it to " +
|
||||||
|
"UNDEFINED. ordinal={}", ordinal);
|
||||||
|
return new DaoPhase(Phase.UNDEFINED, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DaoPhase(Phase.values()[ordinal], proto.getDuration());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue