Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-371

NPE in Predicate.resolve(exchange) when invoked several times

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.1.3.Final, 1.2.0.Beta9
    • 1.1.0.Final, 1.2.0.Beta6
    • Core
    • None
    • Hide

      instantiate 2 PathPrefixPredicate

      on any request, invoke p1.resolve(exchange) than p2.resolve(exchange)

      the second invocation should throw the NPE

      Show
      instantiate 2 PathPrefixPredicate on any request, invoke p1.resolve(exchange) than p2.resolve(exchange) the second invocation should throw the NPE
    • Workaround Exists
    • Hide

      invoke first the method
      private void fixExchangeForUndertowBug(HttpServerExchange exchange)

      { if (exchange.getAttachment(Predicate.PREDICATE_CONTEXT) == null) exchange.putAttachment(Predicate.PREDICATE_CONTEXT, new HashMap<String, Object>()); }
      Show
      invoke first the method private void fixExchangeForUndertowBug(HttpServerExchange exchange) { if (exchange.getAttachment(Predicate.PREDICATE_CONTEXT) == null) exchange.putAttachment(Predicate.PREDICATE_CONTEXT, new HashMap<String, Object>()); }
    • Low

      I have few PathPrefixPredicate instantiated with PredicateParser.parse

      I use them to check if a request should be allowed (predicate as security permissions) in following code

      public boolean isAllowed(HttpServerExchange exchange))

      { ..... return roles(exchange).anyMatch(role -> aclForRole(role).stream().anyMatch(p -> p.resolve(exchange))); }

      The first p.resolve invocation goes as expected. The second throws a NPE:

      java.lang.NullPointerException: null at io.undertow.predicate.PathPrefixPredicate.resolve(PathPrefixPredicate.java:55)

      the fact is that Map<String, Object> context = value.getAttachment(PREDICATE_CONTEXT); return null so the NPE.

      if I invoke the following method before iterating through the predicates, it goes fine:

      private void fixExchangeForUndertowBug(HttpServerExchange exchange)

      { if (exchange.getAttachment(Predicate.PREDICATE_CONTEXT) == null) exchange.putAttachment(Predicate.PREDICATE_CONTEXT, new HashMap<String, Object>()); }

      The code was working with undertow-core 1.0

              sdouglas1@redhat.com Stuart Douglas (Inactive)
              a.dicesare@softinstigate.com Andrea Di Cesare (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: