Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-978

Configuration variable & literal parsing errors



    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • None
    • 1.1.2
    • logback-core
    • None
    • All


      When logback attempts to substitute values in for variables (of of the style ${...}) in the body of an element in logback.xml, if the body String ends with a dollar sign, '$', line 63 of ch.qos.logback.core.subst.Tokenizer performs:

      throw new ScanException("Unexpected end of pattern string");

      Which incorrectly throws a ScanException, because it is incorrectly expecting more characters, either a '{' to tell it to expect a variable name, or not a '{', to indicate that the '$' was a literal. If a '$' is the last character, obviously it is a literal instead of the beginning of a variable reference token.

      Also, if the body String ends with "${", an NPE is thrown by some other method. Instead, my solution below throws a ScanException in this case (plus for the case where a "${" is not closed by a "}").

      Lastly, if the String includes unbalanced '

      {' without corresponding closing '}

      ', your code throws exceptions elsewhere. Why must '

      {' be balanced by closing '}

      ', if the '{' is not preceded by a '$'? My solution doesn't fix this issue, only the previous issues. Assuming my solution works for the earlier issues, however, it should be put into place, and the latter '{' issue can be handled later.

      Solution (not tested or even compiled, so it might contain typos):
      The body of the switch statement that include line 63 should probably be replaced with something like the following:

      case LITERAL_STATE:
      final int tokenCount = tokenList.size();
      if (tokenCount >= 2 && tokenList.get(tokenCount - 2) == Token.START_TOKEN) {
      throw new ScanException("variable reference open, \"${\", without a variable reference close, \"}\" for variable name " + buf);
      addLiteralToken(tokenList, buf);
      case START_STATE:
      addLiteralToken(tokenList, buf);




            logback-dev Logback dev list
            rgoldberg Ross Goldberg
            4 Vote for this issue
            7 Start watching this issue