title: Is this a redundant NullPointerException catch?
body: <p>Below Spring REST code returns List for a given ticketId. </p>
  
  <p>Could a <code>NullPointerException</code> be thrown in this code ? </p>
  
  <p><code>NullPointerException</code> explicitly caught in <code>TicketController</code>:</p>
  
  <pre><code>    catch (NullPointerException nullPointerException) {
          throw new ResponseStatusException(
              HttpStatus.BAD_REQUEST, nullPointerException.getMessage(), nullPointerException);
      }
  </code></pre>
  
  <p>The thinking may have been when checking for null on the ticket id: </p>
  
  <pre><code>        if (ticketId == null) {
              throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "ticket id cannot be null");
          }
  </code></pre>
  
  <p>the expectation is that a <code>NullPointerException</code> would be thrown but instead a <code>ResponseStatusException</code> is thrown ?</p>
  
  <p>If the variable <code>ticketId</code> is a path parameter it can never be null as hit the base url <code>/</code> without a <code>ticketId</code> I receive:</p>
  
  <pre><code>There was an unexpected error (type=Method Not Allowed, status=405).
  </code></pre>
  
  <p>Entire source:</p>
  
  <pre><code>@RestController
      public class TicketController {
  
          private final TicketServiceImpl ticketServiceImpl;
  
          public TicketController(TicketServiceImpl ticketServiceImpl) {
              this.ticketServiceImpl = ticketServiceImpl;
          }
  
          @GetMapping(path = "/{ticketId}")
          public ResponseEntity&lt;List&lt;TicketResponse&gt;&gt; getTicketsById(
              @PathVariable("ticketId") final Long ticketId) {
              try {
                  final List&lt;TicketResponse&gt; ticketsById = ticketServiceImpl.getAll(ticketId);
                  return new ResponseEntity&lt;&gt;(ticketsById, HttpStatus.OK);
              }
              catch (NullPointerException nullPointerException) {
                  throw new ResponseStatusException(
                      HttpStatus.BAD_REQUEST, nullPointerException.getMessage(), nullPointerException);
              }
              catch (TicketNotFoundException ticketNotFoundException) {
                  throw new ResponseStatusException(
                      HttpStatus.NOT_FOUND, "Ticket id not found",
                      ticketNotFoundException);
              }
  
          }
  
      }
  
  @Service
  public class TicketServiceImpl implements TicketService {
  
      private final TicketRepository ticketRepository;
  
      public TicketServiceImpl(TicketRepository ticketRepository) {
  
          this.ticketRepository = ticketRepository;
  
      }
  
      @Override
      public List&lt;TicketResponse&gt; getAll(Long ticketId) {
  
          final List&lt;TicketResponse&gt; ticketResponselist = ticketRepository.findData(ticketId);
  
              if (ticketId == null) {
                  throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "ticket id cannot be null");
              }
              else if (ticketResponselist.size() == 0) {
                  throw new TicketNotFoundException("ticket not found");
              }
              else {
                  return ticketResponselist;
              }
  
      }
  }
  
  @Repository
  public interface TicketRepository {
  
      public List&lt;TicketResponse&gt; findData(Long ticketId);
  
  }
  </code></pre>