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

Unboxing in return from lambda miscompiled to throw ClassCastException

XMLWordPrintable

    • b19
    • generic
    • generic
    • Verified

        A DESCRIPTION OF THE PROBLEM :
        In this example a lambda Comparable (so with return type int) returns a Character. This should cause unboxing and then conversion to int. But javac generates code that instead tries to convert the Character to Integer before the unboxing, leading to an unexpected ClassCastException


        ---------- BEGIN SOURCE ----------
        List.of('x', 'y').stream()
          .max((a, b) -> {return List.of(a).get(0);});
        ---------- END SOURCE ----------

        FREQUENCY : always


              bsrbnd Bernard Blaser
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: