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

javac throws NullPointerException in the provided code

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      windows 10 version 20H2,


      A DESCRIPTION OF THE PROBLEM :
      there is no error in program but it throws null pointer exception.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      to run smoothly.

      ---------- BEGIN SOURCE ----------
      //TO DO: Complete this class, add JavaDocs

      //Do not add any more imports!
      import java.util.Iterator;
      import java.util.Set;

      public class MemMan implements Iterable<MemBlock> {

      //******************************************************
      //**** IMPORTANT: DO NOT CHANGE/ALTER/REMOVE ****
      //**** ANYTHING PROVIDED LIKE THESE INTS HERE... ****
      //******************************************************

      public static final int FIRST_FIT = 0;
      public static final int BEST_FIT = 1;
      public static final int WORST_FIT = 2;
      public static final int NEXT_FIT = 3;

      public static BareNode head;

      //******************************************************
      //**** IMPORTANT: DO NOT CHANGE/ALTER/REMOVE ****
      //**** ANYTHING PROVIDED LIKE THE INSTANCE ****
      //**** VARIABLES IN THIS NESTED CLASS. ALSO ****
      //**** DON'T REMOVE THE CLASS ITSELF OR ANYTHING ****
      //**** STRANGE LIKE THAT. ****
      //******************************************************

      public static class BareNode {

      public MemBlock block;
      public BareNode next;
      public BareNode prev;
      public boolean marked;

      public BareNode(MemBlock block) {
      this.block = block;
      }
      }

      public BareNode getHead(){
      return head;

      }

      public BareNode malloc(int size){



      BareNode node = new BareNode(new MemBlock(0,size,false));

      node.next=head;
      node.prev=null;

      if(head!= null){
      head.prev=node;
      }

      head=node;
      return node;

      }

      public BareNode realloc(BareNode oldBn, int size){


           BareNode bNode = oldBn;
          
           bNode.block.size=size;

          
           return bNode;

      }


      public int garbageCollect(Set<Integer> addrs){

      return 2;
      }
      public boolean free(BareNode node){
      return true;
      }
      public static MemMan factory(int fit, BareNode head){

      this.head= head;
      }


      public MemMan iterator() {
      return new LinkedListIterator();
      }

      private class LinkedListIterator implements Iterator<MemBlock> {
             
              private BareNode current = head;

              public MemBlock next() {
                  if (!hasNext()) {
                   throw new NoSuchElementException();
                  }
                  MemBlock item = current.block;
                  current = current.next;
                  return item;
              }

              public boolean hasNext() {
               return current != null;
              }

              public void remove() {
               throw new UnsupportedOperationException();
              }
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      i have not found anyone.

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            adev ANUPAM DEV
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: