Methods with return type List may return null

Issue #58 closed
Tomas Laubr created an issue

E.g. JwtClaims.getAudience() may return null. It's a bad practice and it complitaces usage of the library. Empty list should be returned instead.

Comments (8)

  1. Brian Campbell repo owner

    Though it's probably unlikely to happen in practice, there are semantic differences between a claim with an empty list value and a claim that's not present in the JWT. The request makes sense but I'll need to do some looking to try and make sure it wouldn't break anything.

  2. Tomas Laubr reporter

    What is the semantic difference between an empty list claim and a claim that is not present at all?

  3. Brian Campbell repo owner

    Depends on the definition of the claim but, for example, the token is only audience restricted if the aud claim is present (http://tools.ietf.org/html/rfc7519#section-4.1.3). No aud claim means no audience restriction. Though not really a realistic case, "aud": [] would mean that the token audience restricted but for no one. The AudValidator https://bitbucket.org/b_c/jose4j/src/539a4f45e2c2bfc18ec3a55b8a69810bdec92d89/src/main/java/org/jose4j/jwt/consumer/AudValidator.java?at=master&fileviewer=file-view-default currently relies on getAudience() retuning null to indicate that there was no aud claim.

  4. Brian Campbell repo owner

    fixed with eb45795 "addressing Issue #58 by having JwtClaims getAudience() and getStringListClaimValue(name) return an empty list rather than null when the claim isn’t present"

  5. Log in to comment