Uploaded image for project: 'Clojure'
  1. CLJ-1212

Silent truncation/downcasting of primitive type on reflection call to overloaded method (Math/abs)

    Details

    • Type: Bug
    • Status: Reopened
    • Priority: Major
    • Resolution: Unresolved
    • Affects versions: Release 1.5
    • Fix versions: None
    • Environment:

      Clojure 1.5.1
      OpenJDK Runtime Environment (IcedTea6 1.12.5) (6b27-1.12.5-0ubuntu0.12.04.1)

      Description

      I realise relying on reflection when calling these kinds of methods isn't a great idea performance-wise, but it shouldn't lead to incorrect or dangerous behaviour.

      Here it seems to trigger a silent downcast of the input longs, giving a truncated integer output:

      user> (defn f [a b] (Math/abs (- a b)))
      Reflection warning, NO_SOURCE_PATH:1:15 - call to abs can't be resolved.
      #'user/f
      user> (f 1000000000000 2000000000000)
      727379968
      user> (class (f 1000000000000 2000000000000))
      java.lang.Integer
      user> (defn f [^long a ^long b] (Math/abs (- a b)))
      #'user/f
      user> (f 1000000000000 2000000000000)
      1000000000000
      user> (class (f 1000000000000 2000000000000))
      java.lang.Long

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: