microg/GmsCore · error · IllegalArgumentException
Not a bytes type
Error message
Not a bytes type
What it means
Flag.getBytes() throws IllegalArgumentException("Not a bytes type") when the flag's dataType is not DATA_TYPE_BYTES. The bytes accessor validates the dataType discriminator before returning bytesValue; reading byte-array content from any other kind of flag is rejected as a caller bug.
Source
Thrown at play-services-phenotype/src/main/java/com/google/android/gms/phenotype/Flag.java:95
throw new IllegalArgumentException("Not a boolean type");
}
public double getDouble() {
if (dataType == DATA_TYPE_DOUBLE)
return doubleValue;
throw new IllegalArgumentException("Not a double type");
}
public String getString() {
if (dataType == DATA_TYPE_STRING)
return stringValue;
throw new IllegalArgumentException("Not a String type");
}
public byte[] getBytes() {
if (dataType == DATA_TYPE_BYTES)
return bytesValue;
throw new IllegalArgumentException("Not a bytes type");
}
public static final int DATA_TYPE_LONG = 1;
public static final int DATA_TYPE_BOOL = 2;
public static final int DATA_TYPE_DOUBLE = 3;
public static final int DATA_TYPE_STRING = 4;
public static final int DATA_TYPE_BYTES = 5;
public static final Creator<Flag> CREATOR = findCreator(Flag.class);
}
View on GitHub (pinned to 157c9d86ac)
Solutions
- Guard with flag.getDataType() == Flag.DATA_TYPE_BYTES before calling getBytes()
- If the flag may be a string, fall back to flag.getString().getBytes(StandardCharsets.UTF_8)
- Switch over DATA_TYPE_* constants and handle the BYTES case explicitly
- Verify the server-side flag is defined as a bytes/bytearray type
Example fix
// before
byte[] raw = flag.getBytes();
// after
byte[] raw = flag.getDataType() == Flag.DATA_TYPE_BYTES
? flag.getBytes()
: flag.getString().getBytes(StandardCharsets.UTF_8); Defensive patterns
Strategy: type-guard
Validate before calling
if (flag.getDataType() != Flag.DATA_TYPE_BYTES) { throw new IllegalStateException("flag is not bytes: " + flag.getDataType()); } Type guard
static boolean isBytesFlag(Flag f) { return f != null && f.getDataType() == Flag.DATA_TYPE_BYTES; } Try / catch
try { byte[] v = flag.getBytes(); } catch (IllegalArgumentException e) { log.warn("Flag type mismatch", e); v = EMPTY_BYTES; } Prevention
- Check dataType == DATA_TYPE_BYTES before getBytes()
- Convert string flags explicitly with a named charset instead of assuming bytes
- Confirm binary flags are serialized as byte arrays end-to-end
- Handle DATA_TYPE_* exhaustively in flag decoding code
When it happens
Trigger: Calling Flag.getBytes() on a Flag whose dataType is DATA_TYPE_LONG (1), DATA_TYPE_BOOL (2), DATA_TYPE_DOUBLE (3), or DATA_TYPE_STRING (4) instead of DATA_TYPE_BYTES (5).
Common situations: Assuming a binary/certificate-style flag is stored as bytes when the server defines it as a string; generic flag iteration that calls getBytes() unconditionally; confusion between string and bytes flags after a server config change.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06).
Data as JSON: /api/errors/0c2d41e21ad9762a.
Report an issue: GitHub.