wasabeef/android-gpuimage · error · IllegalStateException

is an unknown rotation. Needs to be either 0, 90, 180 or…

Error message

<rotation> is an unknown rotation. Needs to be either 0, 90, 180 or 270!

What it means

Rotation.fromInt(int) converts an integer (0, 90, 180, 270 — 360 maps back to NORMAL) to the Rotation enum. Any other value throws IllegalStateException("<rotation> is an unknown rotation. Needs to be either 0, 90, 180 or 270!") with the offending value in the message.

Solutions

  1. Normalize the angle before calling: ((angleDegrees % 360) + 360) % 360 so values like -90 become 270.
  2. Convert EXIF orientation constants (1-8) to degrees 0/90/180/270 before invoking fromInt().
  3. Use the normalization helper (Rotation.NORMAL/ROTATION_90...) or guard with a validity check: deg % 90 == 0 && deg in 0..270.

Example fix

// before
 Rotation rot = Rotation.fromInt(exifOrientation); // exifOrientation is 1..8
// after
 int degrees = exifDegreesFromOrientation(exifOrientation); // maps 1..8 to 0/90/180/270
 Rotation rot = Rotation.fromInt(((degrees % 360) + 360) % 360);
Defensive patterns

Strategy: validation

Validate before calling

int normalized = ((degrees % 360) + 360) % 360;
if (normalized != 0 && normalized != 90 && normalized != 180 && normalized != 270) {
    throw new IllegalArgumentException("degrees must be a multiple of 90: " + degrees);
}
Rotation rotation = Rotation.fromInt(normalized);

Try / catch

try {
    Rotation rotation = Rotation.fromInt(degrees);
} catch (IllegalStateException e) {
    Rotation rotation = Rotation.NORMAL; // safe default on bad input
}

Prevention

When it happens

Trigger: Calling Rotation.fromInt() with values like 45, -90, or an EXIF orientation code not converted to degrees first — e.g. passing raw android.media.ExifInterface orientation constants (1-8) instead of computed degrees.

Common situations: Mapping camera sensor or EXIF metadata to rotations without converting orientation codes to degrees; applying an arbitrary user-chosen angle; sign errors producing negative rotation values.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of wasabeef/android-gpuimage@ceea576ec9 (2026-09-11). Data as JSON: /api/errors/16f13496542a964a. Report an issue: GitHub.

Appendix: source

Thrown at library/src/main/java/jp/co/cyberagent/android/gpuimage/util/Rotation.java:61

     * Create a Rotation from an integer. Needs to be either 0, 90, 180 or 270.
     *
     * @param rotation 0, 90, 180 or 270
     * @return Rotation object
     */
    public static Rotation fromInt(int rotation) {
        switch (rotation) {
            case 0:
                return NORMAL;
            case 90:
                return ROTATION_90;
            case 180:
                return ROTATION_180;
            case 270:
                return ROTATION_270;
            case 360:
                return NORMAL;
            default:
                throw new IllegalStateException(
                        rotation + " is an unknown rotation. Needs to be either 0, 90, 180 or 270!");
        }
    }
}

View on GitHub (pinned to ceea576ec9)