From: Tuukka Lehtonen Date: Thu, 26 Sep 2019 13:02:39 +0000 (+0300) Subject: Make ValueFormat.toFormat safe to call with any noOfDecimals value X-Git-Tag: v1.43.0~136^2~63 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=3a1169e5b601f99d66cadaf398329fde9cc8e14a;p=simantics%2Fplatform.git Make ValueFormat.toFormat safe to call with any noOfDecimals value noOfDecimals is now capped between [0,16]. gitlab #391 Change-Id: Id24752a908b65c261f02964ec18cdb8e759ea0d0 (cherry picked from commit 83249a1e50b8ea706fde5e3074856fbf5f9eb1ac) --- diff --git a/bundles/org.simantics.utils/src/org/simantics/utils/format/ValueFormat.java b/bundles/org.simantics.utils/src/org/simantics/utils/format/ValueFormat.java index 9734d3c56..1cc1c94a7 100644 --- a/bundles/org.simantics.utils/src/org/simantics/utils/format/ValueFormat.java +++ b/bundles/org.simantics.utils/src/org/simantics/utils/format/ValueFormat.java @@ -35,10 +35,10 @@ public enum ValueFormat { public Format toFormat( int noOfDecimals ) { switch ( this ) { - case Currency: return noOfDecimals>decimalFormats.length||noOfDecimals<0 ? decimalFormats[decimalFormats.length-1] : decimalFormats[noOfDecimals]; + case Currency: return noOfDecimals>decimalFormats.length||noOfDecimals<0 ? decimalFormats[decimalFormats.length-1] : decimalFormats[Math.min(noOfDecimals, 16)]; case Scientific: return format; case Engineering: return format; - case Default: return noOfDecimals>defaultFormats.length||noOfDecimals<0 ? defaultFormats[defaultFormats.length-1] : defaultFormats[noOfDecimals]; + case Default: return noOfDecimals>defaultFormats.length||noOfDecimals<0 ? defaultFormats[defaultFormats.length-1] : defaultFormats[Math.min(noOfDecimals, 16)]; default: return format; } }