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

Compiler error: Error:java: java.lang.ClassCastException: com.sun.tools.javac.code.Symtab$4 cannot be cast to javax.lang.model.element.TypeE

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      Information:javac 1.8.0_40 was used to compile java sources

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      I am compiling a piece of code with various errors, but besides normal error messages about the errors in my code, I also receive an internal compiler error.

      I receive the following messages about errors in my code as expected (line numbers are off due to editing)

      Error:(16, 17) java: method x in class saganaki.t0006_internet.X cannot be applied to given types;
        required: no arguments
        found: (t)->new X()::run
        reason: actual and formal argument lists differ in length
      Error:(16, 25) java: invalid method reference
        cannot find symbol
          symbol: method run()
          location: class saganaki.t0006_internet.X

      but before those errors I receive this:

      Error:java: java.lang.ClassCastException: com.sun.tools.javac.code.Symtab$4 cannot be cast to javax.lang.model.element.TypeElement


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      paste the code snippet given below in a source file and compile. (Actually, I am using IntelliJ IDEA, but it says "Information:javac 1.8.0_40 was used to compile java sources", so I assume it will also happen if I just use javac by myself. But testing that would require, ugh, command line. ew.)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I should have received only errors about mistakes in my code.
      ACTUAL -
      Besides the errors in my code, there was a compiler error.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Error:java: java.lang.ClassCastException: com.sun.tools.javac.code.Symtab$4 cannot be cast to javax.lang.model.element.TypeElement

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      final class X
      {
      X()
      {
      }

      static void x()
      {
      x( t -> new X()::run );
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      The internal compiler error does not occur if I give it valid java to crunch.

        1. X.java
          0.1 kB
          Fairoz Matte

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

              Created:
              Updated:
              Resolved: