This is an automated email from the ASF dual-hosted git repository.

benw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git


The following commit(s) were added to refs/heads/master by this push:
     new 4ecadd1f5 TAP5-2759: JSONObject#getLongOrDefault argument type fixed
4ecadd1f5 is described below

commit 4ecadd1f5b762e663544c2206640640af5cd3aca
Author: Ben Weidig <b...@netzgut.net>
AuthorDate: Sat Sep 2 11:42:09 2023 +0200

    TAP5-2759: JSONObject#getLongOrDefault argument type fixed
---
 .../java/org/apache/tapestry5/json/JSONObject.java    |  2 +-
 .../src/test/groovy/json/specs/JSONObjectSpec.groovy  | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git 
a/tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java 
b/tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java
index b639b8596..b9ac448bd 100644
--- a/tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java
+++ b/tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java
@@ -538,7 +538,7 @@ public final class JSONObject extends JSONCollection 
implements Map<String, Obje
      *                       to a long.
      * @since 5.7
      */
-    public long getLongOrDefault(String name, int defaultValue)
+    public long getLongOrDefault(String name, long defaultValue)
     {
         Object object = opt(name);
         if (object == null)
diff --git a/tapestry-json/src/test/groovy/json/specs/JSONObjectSpec.groovy 
b/tapestry-json/src/test/groovy/json/specs/JSONObjectSpec.groovy
index e602327db..8c1516702 100644
--- a/tapestry-json/src/test/groovy/json/specs/JSONObjectSpec.groovy
+++ b/tapestry-json/src/test/groovy/json/specs/JSONObjectSpec.groovy
@@ -9,6 +9,7 @@ import org.apache.tapestry5.json.exceptions.JSONSyntaxException
 import org.apache.tapestry5.json.exceptions.JSONTypeMismatchException
 import org.apache.tapestry5.json.exceptions.JSONValueNotFoundException
 
+import spock.lang.Issue
 import spock.lang.Specification
 import spock.lang.Unroll
 
@@ -946,4 +947,22 @@ class JSONObjectSpec extends Specification {
 
         source == copy
     }
+
+    @Issue("TAP5-2759")
+    def "getLongOrDefault correct type for default value"() {
+               // This test seems obvious, but it fails if the 
getLongOrDefault method
+               // isn't using long as the type for the default value in its 
method declaration
+               given:
+
+               def object = new JSONObject()
+               def defaultValue = 2_147_483_648L
+
+        when:
+
+        def value = object.getLongOrDefault("key", defaultValue)
+
+        then:
+
+        value == defaultValue
+    }
 }

Reply via email to