title: Intrinsic candidate static method reference disappears after a while?
body: <p>I have the following <code>Comparator</code> implemenation:</p>
  <pre><code>private static final class ValueComparator&lt;Value_, Point_ extends Comparable&lt;Point_&gt;&gt; implements Comparator&lt;Value_&gt; {
  
      private final Function&lt;Value_, Point_&gt; indexFunction;
  
      public ValueComparator(Function&lt;Value_, Point_&gt; indexFunction) {
          this.indexFunction = Objects.requireNonNull(indexFunction);
      }
  
      @Override
      public int compare(Value_ o1, Value_ o2) {
          if (o1 == o2) {
              return 0;
          }
          Point_ point1 = indexFunction.apply(o1);
          Point_ point2 = indexFunction.apply(o2);
          if (point1 == point2) {
              return 0;
          }
          int comparison = point1.compareTo(point2);
          if (comparison != 0) {
              return comparison;
          }
          // Identity Hashcode for duplicate protection; we must always include duplicates.
          // Ex: two different games on the same time slot
          int identityHashCode1 = System.identityHashCode(o1);
          int identityHashCode2 = System.identityHashCode(o2);
          return Integer.compare(identityHashCode1, identityHashCode2);
      }
  }
  </code></pre>
  <p>This code runs for a while, and then suddenly throws an NPE - <code>indexFunction</code> somehow becomes <code>null</code>, even though it was checked to be non-null in the constructor.</p>
  <p>Obviously, this was bugging me, so I went looking, and I found that the <code>indexFunction</code> is <code>Math::abs</code>, a reference to a static method. And <code>java.lang.Math.abs(int)</code> is <code>@HotSpotIntrinsicCandidate</code>.</p>
  <p>Does that mean that HotSpot has, at some point, intrinsified the method and therefore the method reference became invalid? How do I protect myself against this sort of thing?</p>
  <pre><code>$ java -version
  openjdk version &quot;11.0.12&quot; 2021-07-20
  OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
  OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)
  </code></pre>