zafarkhaja/jsemver

LexerException constructed with null input

haydin505 opened this issue · 1 comments

I've inspected the code and couldn't figure out how the exception thrown with null input value.

Stack Trace

com.github.zafarkhaja.semver.expr.LexerException: null
	at com.github.zafarkhaja.semver.expr.Lexer.tokenize(Lexer.java:218)
	at c.github.zafarkhaja.semver.expr.ExpressionParser.parse(ExpressionParser.java:86)
	at c.github.zafarkhaja.semver.expr.ExpressionParser.parse(ExpressionParser.java:43)
	at com.github.zafarkhaja.semver.Version.satisfies(Version.java:325)

Corresponding method:
com.github.zafarkhaja.semver.expr.Lexer#tokenize

  Stream<Token> tokenize(String input) {
      List<Token> tokens = new ArrayList<>();
      int tokenPos = 0;
      while (!input.isEmpty()) {
          boolean matched = false;
          for (Token.Type tokenType : Token.Type.values()) {
              Matcher matcher = tokenType.pattern.matcher(input);
              if (matcher.find()) {
                  matched = true;
                  input = matcher.replaceFirst("");
                  if (tokenType != Token.Type.WHITESPACE) {
                      tokens.add(new Token(
                          tokenType,
                          matcher.group(),
                          tokenPos
                      ));
                  }
                  tokenPos += matcher.end();
                  break;
              }
          }
          if (!matched) {
              throw new LexerException(input);
          }
      }
      tokens.add(new Token(Token.Type.EOI, null, tokenPos));
      return new Stream<>(tokens.toArray(new Token[0]));
  }

This is a duplicate of #38. Already fixed for 0.10.0.