Math/max strange behavior while using OpenJ9

Description

When using `Math/max` on OpenJ9, there's a really strange behavior: if I define a var beforehand, it breaks `Math/max`. There's an example below, with Clojure and JVM versions:

Environment

Linux (Ubuntu 16.04)
Eclipse OpenJ9 VM 1.8.0_181-b13

Activity

Show:
import
September 1, 2018, 2:27 AM

Comment made by: mauricio.szabo

You can work-around this issue using Clojure's `max` function, but this could affect other Java interop on J9

Alex Miller
September 1, 2018, 3:07 AM

In the first line, the numbers are parsed as longs and that type info is available when choosing the overloaded method of Math/max. In the last case a and b are typed as Objects, so you fall into reflection. (You can see this if you (set! warn-on-reflection true)).

My guess is that reflection is picking an unintended override, probably because it's choosing based on some arbitrary ordering that happens to be different than other jdks.

As with any reflective case, you can stop getting arbitrary results by providing type hints on a and b:

Or in the max call directly:

Alex Miller
September 1, 2018, 3:08 AM

I don't think there's really anything to do here, and I don't think it's actually specific to J9.

Declined

Assignee

Unassigned

Reporter

import

Labels

None

Approval

None

Patch

None

Affects versions

Priority

Minor