title: Exception in thread "main" java.lang.StackOverflowError (Create Breakpoint)
body: <p>It is a simple library code where books are added in library list. find method that returns boolean values. borrowed method that delete book from libraryList and moves book to borrowedList. return method removes book from borrowedList and moves book back to libraryList. I am using IntelliJ and code is under default package. Please help me pinpoint the problem and solve it. Thank you.</p>
  <p>LibraryDriver.java</p>
  <pre><code>import java.util.Scanner;
  public class LibraryDriver 
  {
      LibraryList library = new LibraryList();
      BorrowedList borrowed = new BorrowedList();
      Book b;
  
      public void addBook(Scanner in){
          System.out.println(&quot;Enter Books's ISBN: &quot;);
          int isbn = in.nextInt();
          System.out.println(&quot;Enter Book's Title: &quot;);
          String title = in.next();
          System.out.println(&quot;Enter Book's Author Name: &quot;);
          String author = in.next();
          b = new Book (isbn, title, author);
          library.addBook(b);
      }
  
      public void findBook(Scanner in){
          System.out.println(&quot;Enter the Books ISBN to search: &quot;);
          int isbn = in.nextInt();
          if(library.findBook(isbn) == true)
          {
              System.out.println(&quot;Book is available in Library&quot;);
          }
          else if(borrowed.findBook(isbn) == true)
          {
              System.out.println(&quot;Book is borrowed by a Student&quot;);
          }
          else
              System.out.println(&quot;Sorry, Book is not available&quot;);
      }
  
      public void borrowBook(Scanner in){
          System.out.println(&quot;Enter the ISBN of Book you want to borrow: &quot;);
          int isbn = in.nextInt();
          if(library.findBook(isbn) == true){
              library.loanBook(isbn);
          }
      }
  
      public void returnBorrowedBook(Scanner in){
          System.out.println(&quot;Enter the ISBN of Book you want to return: &quot;);
          int isbn = in.nextInt();
          if(borrowed.findBook(isbn) == true){
              borrowed.returnBook(isbn);
          }
      }
  
      public void printAllBooks(){
          library.printBook();
          borrowed.printBook();
      }
  
      public static void main(String[] args){
          Scanner in = new Scanner(System.in);
          LibraryDriver driver = new LibraryDriver();
          System.out.println(&quot;Welcome to Murtaza's Library&quot;);
          System.out.println(&quot;--------------------------------&quot;);
          boolean done = false;
          while (!done)
          {
              System.out.print(&quot;Please select an action: (F)ind, (A)dd, (B)orrowed, (P)rint, (R)eturn or (Q)uit: &quot;);
              String choice = in.next();
              if (choice.equals(&quot;F&quot;) || choice.equals(&quot;f&quot;)){
                  driver.findBook(new Scanner(System.in));
              }
              else if (choice.equals(&quot;A&quot;) || choice.equals(&quot;a&quot;)){
                  driver.addBook(new Scanner(System.in));
              }
              else if (choice.equals(&quot;B&quot;) || choice.equals(&quot;b&quot;)){
                  driver.borrowBook(new Scanner(System.in));
              }
              else if (choice.equals(&quot;R&quot;) || choice.equals(&quot;r&quot;)){
                  driver.returnBorrowedBook(new Scanner(System.in));
              }
              else if (choice.equals(&quot;P&quot;) || choice.equals(&quot;p&quot;)){
                  driver.printAllBooks();
              }
              done = choice.equals(&quot;Q&quot;) || choice.equals(&quot;q&quot;);
          }
          System.out.println(&quot;Good bye.Have a nice day!&quot;);
          in.close();
      }
  }
  </code></pre>
  <p>LibraryList.java</p>
  <pre><code>import java.util.LinkedList;
  
  public class LibraryList {
      static private LinkedList&lt;Book&gt;libraryList;
      BorrowedList bList = new BorrowedList();
  
      public LibraryList() {
          libraryList = new LinkedList&lt;Book&gt;();
      }
  
      public void addBook(Book b) {
          libraryList.add(b);
      }
  
      public void loanBook(int isbn){
          for(int i = 0; i &lt; libraryList.size() ;i++){
              if(isbn == libraryList.get(i).getIsbn()){
                  bList.addBook(libraryList.get(i));
                  libraryList.remove(i);
                  System.out.println(&quot;Request has been processed. Collect&quot;);
              }
          }
      }
  
      public boolean findBook(int isbn){
          boolean value = false;
          for(int i = 0; i &lt; libraryList.size();i++){
              if(libraryList.get(i).getIsbn() == isbn){
                  value= true;
                  break;
              }
              else
                  value= false;
          }
          return value;
      }
      public void printBook() {
          System.out.println(&quot;==================================&quot;);
          System.out.println(&quot;All Books in Library are: &quot;);
          System.out.println(&quot;==================================&quot;);
          for(int i = 0; i &lt; libraryList.size();i++){
              System.out.println(libraryList.get(i));
          }
      }
  }
  </code></pre>
  <p>BorrowedList.java</p>
  <pre><code>import java.util.LinkedList;
  
  public class BorrowedList {
      static private LinkedList&lt;Book&gt;borrowedList;
      LibraryList lib = new LibraryList();
  
      public BorrowedList() {
          borrowedList = new LinkedList&lt;Book&gt;();
      }
  
      public void addBook(Book b) {
          borrowedList.add(b);
      }
  
      public void returnBook(int isbn){
          for(int i = 0; i &lt; borrowedList.size() ;i++){
              if(isbn == borrowedList.get(i).getIsbn()){
                  lib.addBook(borrowedList.get(i));
                  borrowedList.remove(i);
                  System.out.println(&quot;Request has been processed.&quot;);
              }
          }
      }
  
      public boolean findBook(int isbn){
          boolean value = false;
          for(int i = 0; i &lt; borrowedList.size();i++){
              if(borrowedList.get(i).getIsbn() == isbn){
                  value= true;
                  break;
              }
              else
                  value= false;
          }
          return value;
      }
  
      public void printBook() {
          System.out.println(&quot;==================================&quot;);
          System.out.println(&quot;All Books Borrowed by Students are: &quot;);
          System.out.println(&quot;==================================&quot;);
          for(int i = 0; i &lt; borrowedList.size();i++){
              System.out.println(borrowedList.get(i));
          }
      }
  }
  </code></pre>
  <p>Book.java</p>
  <pre><code>public class Book {
      private int isbn;
      private String title;
      private String author;
  
      public Book(int isbn, String title, String author) {
          this.isbn = isbn;
          this.title = title;
          this.author = author;
      }
      public int getIsbn() {
          return isbn;
      }
  
      public void setIsbn(int isbn) {
          this.isbn = isbn;
      }
      public String getTitle() {
          return title;
      }
      public void setTitle(String title) {
          this.title = title;
      }
  
      public String getAuthor() {
          return author;
      }
  
      public void setAuthor(String author) {
          this.author = author;
      }
  
      @Override
      public String toString() {
          String str = &quot;&quot;;
          str += &quot;ISBN: &quot; + isbn + &quot;\n&quot;;
          str += &quot;Title: &quot; + title + &quot;\n&quot;;
          str += &quot;Author: &quot; + author + &quot;\n&quot;;
          return str;
      }
  }
  </code></pre>
  <p>Error</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.StackOverflowError
      at BorrowedList.&lt;init&gt;(BorrowedList.java:6)
      at LibraryList.&lt;init&gt;(LibraryList.java:6)
      at BorrowedList.&lt;init&gt;(BorrowedList.java:6)
      at LibraryList.&lt;init&gt;(LibraryList.java:6)
      at BorrowedList.&lt;init&gt;(BorrowedList.java:6)
      at LibraryList.&lt;init&gt;(LibraryList.java:6)
      at BorrowedList.&lt;init&gt;(BorrowedList.java:6)
      at LibraryList.&lt;init&gt;(LibraryList.java:6)
      and keeps repeating.
  </code></pre>