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

Lambda expression with defined type gets treated as final variable

XMLWordPrintable

    • b129
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.8.0-b129)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0-b69, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :

      I have declared this variable:
      private static final Comparator<ItemAuction> ITEM_AUCTION_COMPERATOR = Comparator.comparingLong((ItemAuction entry) -> entry.getStartingTime()).reversed();

      and when return statement is used in constructor compiler considers entry as an initialized variable while its lambda parameter name.

      if return statement is removed everything works fine this happens in catch block i haven't tested if its generally everywhere.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      usage of lambda on static field with defined type and using return statement in constructor (even if field is defined as static)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -

      Compilation error:
      variable entry might not have been initialized
      ACTUAL -
      error: variable entry might not have been initialized

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      error: variable entry1 might not have been initialized

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------


      define:
      private static final Comparator<ItemAuction> ITEM_AUCTION_COMPERATOR = Comparator.comparingLong((ItemAuction entry) -> entry.getStartingTime()).reversed();


      and put this in constructor:
      catch (final SQLException e)
      {
      _log.log(Level.SEVERE, getClass().getSimpleName() + ": Failed loading auctions.", e);
      return;
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      removing return putting all code in try block.

            vromero Vicente Arturo Romero Zaldivar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: