opendataloader-project/opendataloader-pdf · error · IllegalArgumentException

Option --image-resolution requires a finite positive double

Error message

Option --image-resolution requires a finite positive double value.

What it means

Thrown while applying --image-resolution when Double.parseDouble succeeds but the result is non-finite (NaN or +/-Infinity) or non-positive (<=0). The setter Config.setImageResolution has no lower bound of its own, so the CLI layer enforces the finite-and-positive contract here. Valid values are positive decimal DPI numbers (default 144.0).

Source

Thrown at java/opendataloader-pdf-core/src/main/java/org/opendataloader/pdf/api/cli/CLIOptions.java:484

            if (formatValue == null || formatValue.trim().isEmpty()) {
                throw new IllegalArgumentException(
                        "Option --image-format requires a value. Supported values: png, jpeg");
            }
            String format = formatValue.trim().toLowerCase(Locale.ROOT);
            if (!Config.isValidImageFormat(format)) {
                throw new IllegalArgumentException(
                        String.format("Unsupported image format '%s'. Supported values: png, jpeg", format));
            }
            config.setImageFormat(format);
        }
        if (commandLine.hasOption(IMAGE_DIR_LONG_OPTION)) {
            config.setImageDir(commandLine.getOptionValue(IMAGE_DIR_LONG_OPTION));
        }
        if (commandLine.hasOption(IMAGE_RESOLUTION_LONG_OPTION)) {
            try {
                double imageResolution = Double.parseDouble(commandLine.getOptionValue(IMAGE_RESOLUTION_LONG_OPTION));
                if (!Double.isFinite(imageResolution) || imageResolution <= 0) {
                    throw new IllegalArgumentException(
                        "Option --image-resolution requires a finite positive double value.");
                }
                config.setImageResolution(imageResolution);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException(
                    "Option --image-resolution requires valid double value.", e);
            }
        }
    }

    private static void applyPagesOption(Config config, CommandLine commandLine) {
        if (commandLine.hasOption(PAGES_LONG_OPTION)) {
            config.setPages(commandLine.getOptionValue(PAGES_LONG_OPTION));
        }
    }

    private static void applyTableMethodOption(Config config, CommandLine commandLine) {
        if (commandLine.hasOption(TABLE_METHOD_LONG_OPTION)) {

View on GitHub (pinned to a7789b8e77)

Solutions

  1. Use a positive DPI such as `--image-resolution 144.0`.
  2. If computing the value, guard: only pass when value > 0 and Double.isFinite(value).
  3. Omit the flag to use the default 144.0.

Example fix

// before
opendataloader-pdf doc.pdf --image-resolution 0
// after
opendataloader-pdf doc.pdf --image-resolution 144.0
Defensive patterns

Strategy: validation

Validate before calling

String raw = commandLine.getOptionValue("image-resolution");
if (raw != null && !raw.trim().isEmpty()) {
    double d = Double.parseDouble(raw.trim());
    if (!Double.isFinite(d) || d <= 0) {
        throw new IllegalArgumentException("--image-resolution must be finite & positive, got " + d);
    }
    config.setImageResolution(d);
}

Type guard

boolean isAcceptableResolution(String raw) {
    try {
        double d = Double.parseDouble(raw.trim());
        return Double.isFinite(d) && d > 0;
    } catch (NumberFormatException e) {
        return false;
    }
}

Try / catch

try {
    CLIOptions.applyAllTo(config, cmd);
} catch (IllegalArgumentException e) {
    System.err.println(e.getMessage());
    System.exit(2);
}

Prevention

When it happens

Trigger: Pass `--image-resolution 0`, a negative like `--image-resolution -72`, `NaN`, `Infinity`, or a value that parses to a non-positive such as `--image-resolution 0.0`. Scientific notation that underflows to zero also trips this.

Common situations: Script computes DPI and divides by zero yielding Infinity/NaN; a config template leaves a placeholder 0; sign error in arithmetic producing a negative.

Related errors


AI-assisted analysis of opendataloader-project/opendataloader-pdf@a7789b8e77 (2026-08-14). Data as JSON: /api/errors/a002fdf978673c3f. Report an issue: GitHub.