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:
Alex Miller
August 31, 2018, 5:08 PM

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

Alex Miller
August 31, 2018, 5:07 PM

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:

import
August 31, 2018, 4:27 PM

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

Declined
Your pinned fields
Click on the next to a field label to start pinning.

Assignee

Unassigned

Reporter

import

Priority

Minor

Affects versions