quarkusio/quarkus · error · IllegalArgumentException

Unknown image format

Error message

Unknown image format 

What it means

Thrown by ImageResource.image when the requested 'format' path/query parameter does not match any of the image formats handled by the switch statement (jpg, png, gif, bmp, binary, etc.). The default branch rejects any unsupported target format before writing via ImageIO.

Source

Thrown at integration-tests/awt/src/main/java/io/quarkus/awt/it/ImageResource.java:225

                case "GIF":
                case "PNG":
                    ImageIO.write(img, format, bos);
                    break;
                case "JPG":
                case "BMP":
                    // Doesn't handle transparency.
                    final BufferedImage imgBGR = new BufferedImage(img.getWidth(), img.getHeight(), TYPE_3BYTE_BGR);
                    imgBGR.getGraphics().drawImage(img, 0, 0, null);
                    ImageIO.write(imgBGR, format, bos);
                    break;
                case "WBMP":
                    // Handles neither transparency nor colours, it's monochrome.
                    final BufferedImage imgBINARY = new BufferedImage(img.getWidth(), img.getHeight(), TYPE_BYTE_BINARY);
                    imgBINARY.getGraphics().drawImage(img, 0, 0, null);
                    ImageIO.write(imgBINARY, format, bos);
                    break;
                default:
                    throw new IllegalArgumentException("Unknown image format " + format);
            }

            return Response
                    .accepted()
                    .type(MediaType.APPLICATION_OCTET_STREAM_TYPE)
                    .header("Content-Disposition", "attachment; filename=\"picture." + format.toLowerCase() + "\"")
                    .entity(bos.toByteArray())
                    .build();
        }
    }

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/fonts")
    public Response fonts() {
        return Response.ok().entity(Arrays.toString(
                GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames())).build();
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Use one of the supported format values (jpg, png, gif, bmp, binary) for the endpoint.
  2. Fix typos and match the casing the resource expects (e.g. 'jpeg' vs 'jpg' per the switch).
  3. Extend the switch (or register an ImageIO SPI writer) if a new format is genuinely needed.

Example fix

// before
GET /image?format=webp
// after
GET /image?format=png
Defensive patterns

Strategy: validation

Validate before calling

java.util.Set<String> SUPPORTED = java.util.Set.of("jpg", "png", "gif", "bmp", "binary");
if (!SUPPORTED.contains(format)) {
    throw new IllegalArgumentException("format must be one of " + SUPPORTED);
}

Type guard

boolean isSupportedImageFormat(String f) {
    return f != null && java.util.Set.of("jpg", "png", "gif", "bmp", "binary").contains(f.toLowerCase());
}

Try / catch

try {
    Response r = target("/image/" + format).get();
} catch (jakarta.ws.rs.BadRequestException e) {
    log.error("Unsupported image format requested: " + format);
}

Prevention

When it happens

Trigger: Calling the image endpoint with a format value not in the switch, e.g. format=tiff, format=webp, or a misspelled value like 'jepg'.

Common situations: Client using image formats Java ImageIO cannot write natively (TIFF pre-Java9 style assumptions, WebP); typos in the format parameter; case mismatches depending on how the parameter is normalized.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/5dcb4aa31322fcd1. Report an issue: GitHub.