elastic/elasticsearch · error · IllegalArgumentException

Error trying to read [{}#ARGUMENTS]

Error message

Error trying to read [{}#ARGUMENTS]

What it means

After confirming PARAMETERS exists and is of type String[], readArgumentNamesConstant calls Field.get(null) to read its value. If that reflection read throws IllegalArgumentException or IllegalAccessException (e.g. the field is not actually accessible despite being public, or security manager/module access rules block it), it is wrapped and rethrown as this IllegalArgumentException.

Source

Thrown at modules/lang-painless/src/main/java/org/elasticsearch/painless/ScriptClassInfo.java:299

                "Painless needs a constant [String[] PARAMETERS] on all interfaces it implements with the "
                    + "names of the method arguments but ["
                    + iface.getName()
                    + "] doesn't have one.",
                e
            );
        }
        if (false == argumentNamesField.getType().equals(String[].class)) {
            throw new IllegalArgumentException(
                "Painless needs a constant [String[] PARAMETERS] on all interfaces it implements with the "
                    + "names of the method arguments but ["
                    + iface.getName()
                    + "] doesn't have one."
            );
        }
        try {
            return (String[]) argumentNamesField.get(null);
        } catch (IllegalArgumentException | IllegalAccessException e) {
            throw new IllegalArgumentException("Error trying to read [" + iface.getName() + "#ARGUMENTS]", e);
        }
    }
}

View on GitHub (pinned to db6a809a66)

Solutions

  1. Ensure the interface's package is open to the Painless module (add 'opens' / 'requires transitive' as appropriate) or that no SecurityManager blocks reflection.
  2. Verify PARAMETERS is declared directly on the interface as 'public static final String[]' and is not shadowed.
  3. Inspect the chained cause (e original) for the precise IllegalAccess/IllegalArgument reason.

Example fix

// module-info.java — open the package to lang-painless
module my.plugin {
    requires elasticsearch.painless;
    opens com.example.scripts to elasticsearch.painless;
}
Defensive patterns

Strategy: try-catch

Validate before calling

void assertParametersReadable(Class<?> iface) throws Exception {
    Field f = iface.getField("PARAMETERS");
    if (!f.getType().equals(String[].class)) throw new IllegalStateException("wrong type");
    try { f.setAccessible(true); f.get(null); }
    catch (IllegalAccessException e) { throw new IllegalStateException("open the package to lang-painless", e); }
}

Try / catch

try {
    new ScriptClassInfo(lookup, MyScript.class);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Error trying to read")
        && (e.getCause() instanceof IllegalAccessException || e.getCause() instanceof IllegalArgumentException)) {
        fail("Module/access problem reading PARAMETERS: " + e.getCause().getMessage());
    }
    throw e;
}

Prevention

When it happens

Trigger: A PARAMETERS field that exists and is typed String[] but cannot be reflectively read — typically due to Java module-system encapsulation, a SecurityManager denying access, or the field being declared on a class rather than an interface with non-static semantics.

Common situations: Running under a restrictive JPMS module that does not 'opens' the interface's package; custom security manager; field shadowing across interfaces where get(null) resolves ambiguously.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/01525cf1c8d5ddfc. Report an issue: GitHub.