From 4b9f6ce57a9165bf6fba95693b8041a5e95e1b8c Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Tue, 3 Dec 2024 16:11:54 -0500 Subject: [PATCH] remove bounds check on input 'long' values into 'alias: double' (#2421) remove bounds check on input 'long' values into 'alias: double' --- changelog/@unreleased/pr-2421.v2.yml | 5 +++++ .../java/com/palantir/product/AliasedDouble.java | 4 +--- .../java/com/palantir/product/DoubleAliasExample.java | 4 +--- .../java/com/palantir/product/SafeDoubleAliasExample.java | 4 +--- .../test/prefix/com/palantir/product/DoubleAliasExample.java | 4 +--- .../prefix/com/palantir/product/SafeDoubleAliasExample.java | 4 +--- .../java/com/palantir/conjure/java/types/AliasGenerator.java | 4 +--- 7 files changed, 11 insertions(+), 18 deletions(-) create mode 100644 changelog/@unreleased/pr-2421.v2.yml diff --git a/changelog/@unreleased/pr-2421.v2.yml b/changelog/@unreleased/pr-2421.v2.yml new file mode 100644 index 000000000..74f85be0e --- /dev/null +++ b/changelog/@unreleased/pr-2421.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: 'remove bounds check on input ''long'' values into ''alias: double''' + links: + - https://github.com/palantir/conjure-java/pull/2421 diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/AliasedDouble.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/AliasedDouble.java index ce7dd6395..422c64784 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/AliasedDouble.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/AliasedDouble.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; -import com.palantir.conjure.java.lib.SafeLong; import java.math.BigDecimal; import javax.annotation.Nullable; import javax.annotation.processing.Generated; @@ -55,8 +54,7 @@ public static AliasedDouble of(double value) { @JsonCreator(mode = JsonCreator.Mode.DELEGATING) public static AliasedDouble of(long value) { - long safeValue = SafeLong.of(value).longValue(); - return new AliasedDouble((double) safeValue); + return new AliasedDouble((double) value); } @JsonCreator(mode = JsonCreator.Mode.DELEGATING) diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/DoubleAliasExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/DoubleAliasExample.java index b4f4bda83..c5fe9d5dd 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/DoubleAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/DoubleAliasExample.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; -import com.palantir.conjure.java.lib.SafeLong; import java.math.BigDecimal; import javax.annotation.Nullable; import javax.annotation.processing.Generated; @@ -55,8 +54,7 @@ public static DoubleAliasExample of(double value) { @JsonCreator(mode = JsonCreator.Mode.DELEGATING) public static DoubleAliasExample of(long value) { - long safeValue = SafeLong.of(value).longValue(); - return new DoubleAliasExample((double) safeValue); + return new DoubleAliasExample((double) value); } @JsonCreator(mode = JsonCreator.Mode.DELEGATING) diff --git a/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeDoubleAliasExample.java b/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeDoubleAliasExample.java index decb20142..64607d35a 100644 --- a/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeDoubleAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/com/palantir/product/SafeDoubleAliasExample.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; -import com.palantir.conjure.java.lib.SafeLong; import com.palantir.logsafe.Safe; import java.math.BigDecimal; import javax.annotation.Nullable; @@ -58,8 +57,7 @@ public static SafeDoubleAliasExample of(@Safe double value) { @JsonCreator(mode = JsonCreator.Mode.DELEGATING) public static SafeDoubleAliasExample of(@Safe long value) { - long safeValue = SafeLong.of(value).longValue(); - return new SafeDoubleAliasExample((double) safeValue); + return new SafeDoubleAliasExample((double) value); } @JsonCreator(mode = JsonCreator.Mode.DELEGATING) diff --git a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/DoubleAliasExample.java b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/DoubleAliasExample.java index c5d2cfa7d..dbf9e3f77 100644 --- a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/DoubleAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/DoubleAliasExample.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; -import com.palantir.conjure.java.lib.SafeLong; import java.math.BigDecimal; import javax.annotation.Nullable; import javax.annotation.processing.Generated; @@ -55,8 +54,7 @@ public static DoubleAliasExample of(double value) { @JsonCreator(mode = JsonCreator.Mode.DELEGATING) public static DoubleAliasExample of(long value) { - long safeValue = SafeLong.of(value).longValue(); - return new DoubleAliasExample((double) safeValue); + return new DoubleAliasExample((double) value); } @JsonCreator(mode = JsonCreator.Mode.DELEGATING) diff --git a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/SafeDoubleAliasExample.java b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/SafeDoubleAliasExample.java index 36ccd00dc..712489f9e 100644 --- a/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/SafeDoubleAliasExample.java +++ b/conjure-java-core/src/integrationInput/java/test/prefix/com/palantir/product/SafeDoubleAliasExample.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; -import com.palantir.conjure.java.lib.SafeLong; import com.palantir.logsafe.Safe; import java.math.BigDecimal; import javax.annotation.Nullable; @@ -58,8 +57,7 @@ public static SafeDoubleAliasExample of(@Safe double value) { @JsonCreator(mode = JsonCreator.Mode.DELEGATING) public static SafeDoubleAliasExample of(@Safe long value) { - long safeValue = SafeLong.of(value).longValue(); - return new SafeDoubleAliasExample((double) safeValue); + return new SafeDoubleAliasExample((double) value); } @JsonCreator(mode = JsonCreator.Mode.DELEGATING) diff --git a/conjure-java-core/src/main/java/com/palantir/conjure/java/types/AliasGenerator.java b/conjure-java-core/src/main/java/com/palantir/conjure/java/types/AliasGenerator.java index 662cdfabb..6b54069d7 100644 --- a/conjure-java-core/src/main/java/com/palantir/conjure/java/types/AliasGenerator.java +++ b/conjure-java-core/src/main/java/com/palantir/conjure/java/types/AliasGenerator.java @@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableList; import com.palantir.conjure.java.ConjureAnnotations; import com.palantir.conjure.java.Options; -import com.palantir.conjure.java.lib.SafeLong; import com.palantir.conjure.java.util.Javadoc; import com.palantir.conjure.java.util.Packages; import com.palantir.conjure.java.util.Primitives; @@ -148,8 +147,7 @@ public static JavaFile generateAliasType( if (isAliasOfDouble(typeDef)) { CodeBlock longCastCodeBlock = CodeBlock.builder() - .addStatement("long safeValue = $T.of(value).longValue()", SafeLong.class) - .addStatement("return new $T((double) safeValue)", thisClass) + .addStatement("return new $T((double) value)", thisClass) .build(); CodeBlock intCastCodeBlock = CodeBlock.builder()