Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8209363

java.lang.VerifyError on startup

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10; java8 u 181

      A DESCRIPTION OF THE PROBLEM :
      When doing reflection within a return statement, the VerifyError is produced by putting parenthesis around the return value (see code below)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      simply compile and run the code below

      ACTUAL -
      Error: A JNI error has occurred, please check your installation and try again
      Exception in thread "main" java.lang.VerifyError: Bad return type
      Exception Details:
        Location:
          Test.lambda$main$2(Ljava/lang/reflect/Field;)Ljava/lang/String; @10: areturn
        Reason:
          Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'java/lang/String' (from method signature)
        Current Frame:
          bci: @10
          flags: { }
          locals: { 'java/lang/reflect/Field' }
          stack: { 'java/lang/Object' }
        Bytecode:
          0x0000000: 120f 2a01 b600 10b6 0011 b04c 01b0
        Exception Handler Table:
          bci [0, 10] => handler: 11
          bci [0, 10] => handler: 11
        Stackmap Table:
          same_locals_1_stack_item_frame(@11,Object[#40])

              at java.lang.Class.getDeclaredMethods0(Native Method)
              at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
              at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
              at java.lang.Class.getMethod0(Class.java:3018)
              at java.lang.Class.getMethod(Class.java:1784)
              at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
              at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)

      ---------- BEGIN SOURCE ----------
      import java.lang.reflect.Modifier;
      import java.util.Arrays;
      import java.util.Objects;

      /**
       * The {@code Test} class.
       */
      public class Test
      {
        @SuppressWarnings("unused")
        private static final String svnid = "$Id$";

        public static void main(String[] args)
        {
          Arrays.stream(Test.class.getDeclaredFields())
              .filter(f -> f.getType().isAssignableFrom(String.class))
              .filter(f -> (f.getModifiers() & (Modifier.FINAL | Modifier.STATIC)) == (Modifier.FINAL | Modifier.STATIC))
              .map(f -> {
                try
                {
                  return (String.class.cast(f.get(null)));
                }
                catch (IllegalArgumentException | IllegalAccessException e)
                {
                  return null;
                }
              })
              .filter(Objects::nonNull)
              .forEachOrdered(td -> System.out.println(td));
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      modify the return statement in the call to map as follows:

      return String.class.cast(f.get(null));

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              fmatte Fairoz Matte
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: