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

Using _ in try with resources results in ClassFormatError

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      > java -version
      openjdk version "21" 2023-09-19
      OpenJDK Runtime Environment (build 21+35-2513)
      OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      This code is fine:

      ===
        // we are happy if this cooLoginID/password combo can simply bind correctly
              try (var ignored = new AutoCloseableInitialLdapContext(bindEnvironment, connCtls)) {
                  res = true;
              } catch (NamingException e) {
                  log.warn("canBind(username: {}, usernameWithDomain: {}, password: {}) suffered exception while binding: {}", username, usernameWithDomain, password, e.toString());
                  res = false;
              }
      ===

      THIS code results in runtime error:

      ===
              // we are happy if this cooLoginID/password combo can simply bind correctly
              try (var _ = new AutoCloseableInitialLdapContext(bindEnvironment, connCtls)) {
                  res = true;
              } catch (NamingException e) {
                  log.warn("canBind(username: {}, usernameWithDomain: {}, password: {}) suffered exception while binding: {}", username, usernameWithDomain, password, e.toString());
                  res = false;
              }
      ===

      ONLY change: relace 'ignored' with '_'.

      In the first case, javap.exe -verbose -p -l -c .\MY.class, shows the LocalVariableTable with 'ignored'

      ===
           LocalVariableTable:
              Start Length Slot Name Signature
                226 8 7 res Z
                223 33 8 ignored Ltce/ad/AutoCloseableInitialLdapContext;
                256 3 7 res Z
                261 37 8 e Ljavax/naming/NamingException;
                  0 335 0 this Ltce/ad/EnergexActiveDirectoryAuthenticationManager;
                  0 335 1 username Ljava/lang/String;
                  0 335 2 usernameWithDomain Ljava/lang/String;
                  0 335 3 password Ljava/lang/String;
                 69 266 4 principal Ljava/lang/String;
                 90 245 5 bindEnvironment Ljava/util/Hashtable;
                208 127 6 I
                298 37 7 res Z
      ===

      In teh latter case:

      ===
            LocalVariableTable:
              Start Length Slot Name Signature
                226 8 7 res Z
                223 33 8 Ltce/ad/AutoCloseableInitialLdapContext;
                256 3 7 res Z
                261 37 8 e Ljavax/naming/NamingException;
                  0 335 0 this Ltce/ad/EnergexActiveDirectoryAuthenticationManager;
                  0 335 1 username Ljava/lang/String;
                  0 335 2 usernameWithDomain Ljava/lang/String;
                  0 335 3 password Ljava/lang/String;
                 69 266 4 principal Ljava/lang/String;
                 90 245 5 bindEnvironment Ljava/util/Hashtable;
                208 127 6 I
                298 37 7 res Z
      ===

      NOt sure if this is significant?


      CUSTOMER SUBMITTED WORKAROUND :
      don't use _ in try with resources...

            adev Anupam Dev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: