title: Java Regex Matcher encountering NullPointerException, when handed null input
body: <p>I am trying to use the java regex matcher-class and I'm encountering a NullPointerException in my code:</p>
  
  <pre><code>String input = null;
  System.out.println("\nEnter your username: ");
  Matcher matcher = VALID_USERNAME_REGEX.matcher(input); //EXCEPTION IS HERE
  if (matcher.find()) {
      username = input;
  } else {
      input = null;
      System.out.println("\nInvalid input, please try again!");
  }
  </code></pre>
  
  <p><strong>Stack Trace:</strong> (line: 173 is in the above code where the comment "<code>//EXCEPTION IS HERE</code>" is located)</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at java.util.regex.Matcher.getTextLength(Unknown Source)
      at java.util.regex.Matcher.reset(Unknown Source)
      at java.util.regex.Matcher.&lt;init&gt;(Unknown Source)
      at java.util.regex.Pattern.matcher(Unknown Source)
      at org.console.Interface.createAccount(Interface.java:173)
      at org.console.Interface.login(Interface.java:78)
      at org.application.Application.run(Application.java:31)
      at org.application.Application.main(Application.java:37)
  </code></pre>
  
  <p>The value of the input should be what the user enters in the console. The regex should match the input to validate that it meets the regex requirements.</p>