-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restores float <-> decimal conversions in the binary reader #905
Conversation
While the documentation for `IonReader#doubleValue` and `decimalValue` indicates that those methods will throw an exception when then the current value's `IonType` is not `FLOAT` or `DECIMAL` respectively, versions of `ion-java` up to and including v1.10.5 would quietly coerce numeric values to the requested type. The new binary reader implementation hewed to the documentation's stated contract, but this ended up being a breaking change for a small number of users who depended on the previous behavior. This PR restores the previously supported numeric type coercions for `doubleValue`, `decimalValue`, and `bigDecimalValue` and adds unit tests to prevent future regressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of formatting nitpicks, but otherwise good.
@@ -594,6 +593,12 @@ public BigDecimal bigDecimalValue() { | |||
scalarConverter.cast(scalarConverter.get_conversion_fnid(_Private_ScalarConversions.AS_TYPE.decimal_value)); | |||
value = scalarConverter.getBigDecimal(); | |||
scalarConverter.clear(); | |||
} else if (valueTid.type == IonType.FLOAT) { | |||
scalarConverter.addValue(doubleValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit—Indentation is off here.
static Stream<InputStream> testData() { | ||
byte[] textData = "$ion_1_0 42 42e0 42.0".getBytes(StandardCharsets.UTF_8); | ||
byte[] binaryData = { | ||
// Version marker 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit—I think we're trying to use a single level of indentation for cases like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How odd--this is what IntelliJ's auto-formatter chose, but I can't imagine why. Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to Matt's comments, but looks good.
While the documentation for `IonReader#doubleValue` and `decimalValue` indicates that those methods will throw an exception when then the current value's `IonType` is not `FLOAT` or `DECIMAL` respectively, versions of `ion-java` up to and including v1.10.5 would quietly coerce numeric values to the requested type. The new binary reader implementation hewed to the documentation's stated contract, but this ended up being a breaking change for a small number of users who depended on the previous behavior. This PR restores the previously supported numeric type coercions for `doubleValue`, `decimalValue`, and `bigDecimalValue` and adds unit tests to prevent future regressions.
While the documentation for `IonReader#doubleValue` and `decimalValue` indicates that those methods will throw an exception when then the current value's `IonType` is not `FLOAT` or `DECIMAL` respectively, versions of `ion-java` up to and including v1.10.5 would quietly coerce numeric values to the requested type. The new binary reader implementation hewed to the documentation's stated contract, but this ended up being a breaking change for a small number of users who depended on the previous behavior. This PR restores the previously supported numeric type coercions for `doubleValue`, `decimalValue`, and `bigDecimalValue` and adds unit tests to prevent future regressions.
While the documentation for
IonReader#doubleValue
anddecimalValue
indicates that those methods will throw an exception when then the current value'sIonType
is notFLOAT
orDECIMAL
respectively, versions ofion-java
up to and including v1.10.5 would quietly coerce numeric values to the requested type. The new binary reader implementation hewed to the documentation's stated contract, but this ended up being a breaking change for a small number of users who depended on the undocumented behavior.This PR restores the previously supported numeric type coercions for
doubleValue
,decimalValue
, andbigDecimalValue
and adds unit tests to prevent future regressions. It also replaces uses of the deprecated$buildDir
accessor inbuild.gradle.kts
with the now-recommended${layout.buildDirectory}
.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.