Skip to content

Commit

Permalink
Review response: corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
chipkent committed Oct 23, 2024
1 parent cba9e65 commit 232a51c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions engine/function/src/templates/Numeric.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3957,7 +3957,13 @@ public class Numeric {
<#if pt.primitive == "byte" || pt.primitive == "short" || pt.primitive == "int" >
return x;
<#else>
return Math.toIntExact(x);
${pt.primitive} val = Math.toIntExact(x);

if ( isNull(val) ) {
throw new ArithmeticException("Overflow: ${pt.primitive} value will not fit in an int" + x);
}

return val;
</#if>
}
</#if>
Expand All @@ -3978,11 +3984,13 @@ public class Numeric {
<#if pt.primitive == "byte" || pt.primitive == "short" >
return x;
<#else>
if (x > Short.MAX_VALUE || x < Short.MIN_VALUE) {
${pt.primitive} val = (short) x;

if (x > Short.MAX_VALUE || x < Short.MIN_VALUE || isNull(val) ) {
throw new ArithmeticException("Overflow: ${pt.primitive} value will not fit in a short" + x);
}

return (short) x;
return val;
</#if>
}
</#if>
Expand All @@ -4003,11 +4011,13 @@ public class Numeric {
<#if pt.primitive == "byte" >
return x;
<#else>
if (x > Byte.MAX_VALUE || x < Byte.MIN_VALUE) {
${pt.primitive} val = (byte) x;

if (x > Byte.MAX_VALUE || x < Byte.MIN_VALUE || isNull(val) ) {
throw new ArithmeticException("Overflow: ${pt.primitive} value will not fit in a byte" + x);
}

return (byte) x;
return val;
</#if>
}
</#if>
Expand Down

0 comments on commit 232a51c

Please sign in to comment.