From aa676577fc62a497c0f74f743d820bf3b4997b03 Mon Sep 17 00:00:00 2001 From: hamz2a Date: Mon, 11 Dec 2023 11:32:19 +0100 Subject: [PATCH] core: return error when allowance ranges are out of bounds --- .../allowances/AbstractAllowanceWithRanges.java | 9 +++++++++ .../fr/sncf/osrd/reporting/exceptions/ErrorType.java | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/allowances/AbstractAllowanceWithRanges.java b/core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/allowances/AbstractAllowanceWithRanges.java index c4d5106b090..686b2558e79 100644 --- a/core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/allowances/AbstractAllowanceWithRanges.java +++ b/core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/allowances/AbstractAllowanceWithRanges.java @@ -52,6 +52,11 @@ protected AbstractAllowanceWithRanges( this.endPos = endPos; this.capacitySpeedLimit = capacitySpeedLimit; this.ranges = ranges; + for (AllowanceRange range : ranges) { + if (range.beginPos < beginPos || range.endPos > endPos) { + throw new OSRDError(ErrorType.AllowanceRangeOutOfBounds); + } + } } protected abstract Envelope computeCore(Envelope base, EnvelopeSimContext context, double parameter); @@ -114,6 +119,10 @@ else if (!search.hasLoweredHighBound()) /** Apply the allowance to a given envelope. */ @Override public Envelope apply(Envelope base, EnvelopeSimContext context) { + if (base.getBeginPos() > beginPos || base.getEndPos() < endPos) { + throw new OSRDError(ErrorType.AllowanceOutOfBounds); + } + assert base.continuous; // get only the region on which the allowance applies diff --git a/core/osrd-reporting/src/main/java/fr/sncf/osrd/reporting/exceptions/ErrorType.java b/core/osrd-reporting/src/main/java/fr/sncf/osrd/reporting/exceptions/ErrorType.java index 028d84d8b37..a506de123b8 100644 --- a/core/osrd-reporting/src/main/java/fr/sncf/osrd/reporting/exceptions/ErrorType.java +++ b/core/osrd-reporting/src/main/java/fr/sncf/osrd/reporting/exceptions/ErrorType.java @@ -381,6 +381,16 @@ public enum ErrorType { "the path goes over the same track multiple times", ErrorCause.USER ), + AllowanceRangeOutOfBounds( + "allowance_range", + "Allowance ranges are out of bounds", + ErrorCause.USER + ), + AllowanceOutOfBounds( + "allowance", + "Allowance is out of bounds", + ErrorCause.USER + ), ; public final String type;