StandardCharsets.UTF_8 not available on Android before API level 19

Issue #24 resolved
DK created an issue

Using this library on Android I get a NoClassDefFoundError as it can't find the StandardCharsets class (which was added in API 19, https://developer.android.com/reference/java/nio/charset/StandardCharsets.html) while getting the UTF8 constant.

Stacktrace:

  Caused by: java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
            at org.jose4j.lang.StringUtil.getBytesUtf8(StringUtil.java:59)
            at org.jose4j.base64url.internal.apache.commons.codec.binary.BaseNCodec.decode(BaseNCodec.java:341)
            at org.jose4j.base64url.Base64Url.base64UrlDecode(Base64Url.java:46)
            at org.jose4j.base64url.Base64Url.base64UrlDecodeToString(Base64Url.java:40)
            at org.jose4j.base64url.Base64Url.base64UrlDecodeToUtf8String(Base64Url.java:35)
            at org.jose4j.jwx.Headers.setEncodedHeader(Headers.java:107)
            at org.jose4j.jwx.JsonWebStructure.setEncodedHeader(JsonWebStructure.java:113)
            at org.jose4j.jws.JsonWebSignature.setCompactSerializationParts(JsonWebSignature.java:64)
            at org.jose4j.jwx.JsonWebStructure.fromCompactSerialization(JsonWebStructure.java:80)
            at org.jose4j.jwt.consumer.JwtConsumer.process(JwtConsumer.java:234)
            at org.jose4j.jwt.consumer.JwtConsumer.processToClaims(JwtConsumer.java:115)

The offending line is here:

In org.jose4j.lang.StringUtil.java

public static byte[] getBytesUtf8(String string)
    {
        return getBytes(string, StandardCharsets.UTF_8);
    }

Can you please change it so it uses the UTF-8 constant from somewhere else (or create your own UTF_8 constant)

Comments (11)

  1. Brian Campbell repo owner

    I don't have a specific date in mind. But it's probably getting close to time to cut a new release. There are a few other minor enhancements I'd like to make first.

    Can you use the attached jose4j-0.4.2-SNAPSHOT.jar in the meantime?

  2. Log in to comment