title: getiing null pointer exception in PutMapping
body: <p>I have 3 entities User, role and book all bidirectionally connected</p>
  <p>user and role-&gt;manytomany joinTable(user_roles)</p>
  <p>user and book-&gt;manytomany joinTable(book_users)</p>
  <p>I want the user to issue a book means only update the jointable(book_users) columns</p>
  <p>userController</p>
  <p>package com.kk.booklendingapi.booklending1.controller;</p>
  <pre><code>@RestController
  @RequestMapping(&quot;/rest/user&quot;)
  public class UserController {
      
      
      @Autowired
      private BookRepository bookRepository;
      
      @Autowired
      private UserRepository userRepository;
      
      @GetMapping(&quot;/books&quot;)
      public List&lt;Book&gt; getBooks(){
          return bookRepository.findAll();
      }
      
      @GetMapping(&quot;/books/{bookName}&quot;)
      public Book getBooks(@PathVariable String bookName){
          return bookRepository.findByBookName(bookName);
      }
      
      
      //test purpose
      @GetMapping(&quot;/users&quot;)
      public List&lt;OnlyUsersRequest&gt; getUsers(){
          return userRepository.getOnlyUsers();
      }
      
      @PutMapping(&quot;/{userId}&quot;)
      public User issueBookByName(@PathVariable int userId,@RequestBody String bookName){
          Optional&lt;User&gt; optionalUser=userRepository.findById(userId);
          User user=optionalUser.get();
          if(user==null) {
              throw new RuntimeException(&quot;USer Not Found: &quot;+user);
          }
          System.out.println(user.getUsername());
          System.out.println(bookName+&quot; &quot;+bookName.getClass());
          Book theBook=bookRepository.findByBookName(bookName);
          System.out.println(theBook.getbName());
          
          user.addBook(theBook);
          
          return userRepository.save(user);
      }
  
  }
  </code></pre>
  <p>made a custom jpa query in bookrepository that is working fine</p>
  <pre><code>@GetMapping(&quot;/books/{bookName}&quot;)
      public Book getBooks(@PathVariable String bookName){
          return bookRepository.findByBookName(bookName);
      }
  </code></pre>
  <p>then why i am getting nullpointerexception in putMapping</p>
  <p>json url</p>
  <pre><code>http://localhost:8484/rest/user/2
  </code></pre>
  <p>json sending as plain text</p>
  <pre><code>Angular_Avengers
  </code></pre>
  <p>error</p>
  <pre><code>&quot;java.lang.NullPointerException\r\n\tat com.kk.booklendingapi.booklending1.controller.UserController.issueBookByName(UserController.java:60)\r\n\
  </code></pre>