MalformedParametersException for reflection on code compiled with Java 21+

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      macOs (aarch64), Linux (x86_64) and certainly Windows

      A DESCRIPTION OF THE PROBLEM :
      Oracle Java 1.8u471, and not OpenJDK 1.8 u471, suffer from a bug when reading parameters via reflection (`Exceutable::getParameters`).

      There was an existing bug https://bugs.openjdk.org/browse/JDK-8058322, and an existing report for the same problem https://bugs.openjdk.org/browse/JDK-8341145 whioch is due to better adherence to JVMS in Java 21 https://bugs.openjdk.org/browse/JDK-8292275.

      JDK-8058322 received a backport fix https://git.openjdk.org/jdk8u/pull/63. So this is indeed fixed in OpenJDK distributions of 1.8, however Oracle Java do not seem to have received this patch.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Basically, I created a reproducer project here : https://github.com/bric3/malformed-parameters-oracle-8

      But basically take this code, compile it with JDK 21 compiler with `--release 8`, then run it on Oracle Java 1.8, and to compare on another openjdk distribution.


      ---------- BEGIN SOURCE ----------
      public class Reproducer {

          /** Public to ease code-generation. Not meant to be used out of the parent class. */
          public interface MyGenericConsumer<T> {
              void accept(T arg);
          }

          /** Public to ease code-generation. Not meant to be used out of the parent class. */
          public static class DefaultRunnableConsumer implements MyGenericConsumer<Runnable> {
              @Override
              public void accept(final Runnable runnable) {
                  runnable.run();
              }
          }

          public static void main(String[] args) throws NoSuchMethodException {
              // Fails on synthetic method on Oracle 8 u471
              Reproducer.DefaultRunnableConsumer.class.getDeclaredMethod("accept", Object.class).getParameters();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      There are several : using a previous JDK to compile, using `-parameters` on the compiler but this adds too much additional and useless data for some constrained environments.

      FREQUENCY :
      ALWAYS

        1. Reproducer.java
          0.7 kB
          Patricia Tavares

            Assignee:
            Chen Liang
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: