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

NullPointerException at Types.eraseNotNeeded() when compiling a class

    Details

    • Type: Bug
    • Status: New
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u221
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      OS: Windows 10 64 bit

      java version "1.8.0_221"
      Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      NullPointerException occured when compiling a class that implemented java.lang.Iterable.iterator()

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      javac Test.java // where the problematic code (see below) resides in Test.java file

      ACTUAL -
      C:\Users\amartya\Desktop>javac Test.java
      An exception has occurred in the compiler (1.8.0_181). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.NullPointerException
              at com.sun.tools.javac.code.Types.eraseNotNeeded(Types.java:2181)
              at com.sun.tools.javac.code.Types.erasure(Types.java:2174)
              at com.sun.tools.javac.comp.Lower.visitIterableForeachLoop(Lower.java:3500)
              at com.sun.tools.javac.comp.Lower.visitForeachLoop(Lower.java:3378)
              at com.sun.tools.javac.tree.JCTree$JCEnhancedForLoop.accept(JCTree.java:1035)
              at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at com.sun.tools.javac.comp.Lower.translate(Lower.java:2371)
              at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
              at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:162)
              at com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:3561)
              at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
              at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at com.sun.tools.javac.comp.Lower.translate(Lower.java:2371)
              at com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:145)
              at com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2828)
              at com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2737)
              at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
              at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at com.sun.tools.javac.comp.Lower.translate(Lower.java:2371)
              at com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2508)
              at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)
              at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at com.sun.tools.javac.comp.Lower.translate(Lower.java:2371)
              at com.sun.tools.javac.comp.Lower.translate(Lower.java:2390)
              at com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3932)
              at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1512)
              at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1356)
              at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
              at com.sun.tools.javac.main.Main.compile(Main.java:523)
              at com.sun.tools.javac.main.Main.compile(Main.java:381)
              at com.sun.tools.javac.main.Main.compile(Main.java:370)
              at com.sun.tools.javac.main.Main.compile(Main.java:361)
              at com.sun.tools.javac.Main.compile(Main.java:56)
              at com.sun.tools.javac.Main.main(Main.java:42)

      ---------- BEGIN SOURCE ----------
      import java.util.*;
      import java.io.*;

      class Test {

      public static void main(String[] args) {

      MyLinkedList<Integer> list = new MyLinkedList<>();
      list.add(10);
      list.add(20);
      list.add(30);

      for (int x : list)
      System.out.print(x);
      System.out.println();

      System.out.println(list.head.data);
      System.out.println(list.head.next.data);
      System.out.println(list.tail.data);
      System.out.println(list.isEmpty());
      }
      }

      class MyLinkedList<T> implements java.lang.Iterable<T> {

      boolean is_empty;
      int size;
      Node<T> head;
      Node<T> tail;

      MyLinkedList() {

      this.is_empty = true;
      this.size = 0;
      this.head = null;
      this.tail = null;
      }

      public boolean isEmpty() {

      return this.is_empty;
      }

      public void add(T data) {

      Node<T> node = new Node<>(data);

      if (this.head == null) {

      this.is_empty = false;
      this.size = 1;
      this.head = node;
      this.tail = node;
      }

      else {

      this.tail.next = node;
      this.tail.next.prev = this.tail;
      this.tail = this.tail.next;

      ++this.size;
      }
      }

      /*public void remove(T data) {

      if (this.isEmpty() || this.head == null)
      throw new NullPointerException();
      }*/

      public void remove(int index) {

      if (this.isEmpty() || this.head == null)
      throw new NullPointerException();

      if (index == 0) {

      this.head = this.head.next;
      this.head.prev = null;
      --this.size;
      return;
      }

      Node<T> ptr = this.head;
      for (int i = 0; i < (index - 1); ++i) {

      ptr = ptr.next;
      if (ptr == null)
      throw new IndexOutOfBoundsException();
      }

      if (ptr.next == null)
      throw new IndexOutOfBoundsException();

      ptr.next = ptr.next.next;
      if (ptr.next.next != null)
      ptr.next.next.prev = ptr;

      --this.size;
      }

      public void iterator() {}
      }

      class Node<T> {

      T data;
      Node<T> next;
      Node<T> prev;

      Node(T data) {

      this.data = data;
      this.next = null;
      this.prev = null;
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Avoid implementing Iterable interface (which implies, avoid foreach on MyLinkedList class)

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: