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

SwitchBootstraps::mappedEnumLookup constructs unused array

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 24
    • None
    • core-libs
    • None
    • b10

    Description

      In mappedEnumLookup, a local map is created when enumMap.map is null, but it's never assigned to enumMap.map which assumedly is the intent:

          private static <T extends Enum<T>> int mappedEnumLookup(T value, MethodHandles.Lookup lookup, Class<T> enumClass, EnumDesc<?>[] labels, EnumMap enumMap) {
              if (enumMap.map == null) {
                  T[] constants = SharedSecrets.getJavaLangAccess().getEnumConstantsShared(enumClass);
                  int[] map = new int[constants.length];
                  int ordinal = 0;

                  for (T constant : constants) {
                      map[ordinal] = labels.length;

                      for (int i = 0; i < labels.length; i++) {
                          if (Objects.equals(labels[i].constantName(), constant.name())) {
                              map[ordinal] = i;
                              break;
                          }
                      }

                      ordinal++;
                  }
              }
              return enumMap.map[value.ordinal()];
          }

      Since the return statement would throw a NPE if this path was exercised it's unclear if this is covered by tests.

      Attachments

        Issue Links

          Activity

            People

              jlahoda Jan Lahoda
              redestad Claes Redestad
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: