java-native-access/jna · error · java.lang.IllegalArgumentException

The query's property enum has no values.

Error message

The query's property enum has no values.

What it means

WbemcliUtil.WmiQuery.execute(int) validates that the query's generic property enum has at least one constant before connecting to WMI. If the enum class is empty, an IllegalArgumentException is thrown as an "idiot check" to fail fast on a malformed query definition.

Source

Thrown at contrib/platform/src/com/sun/jna/platform/win32/COM/WbemcliUtil.java:180

        /**
         * Query WMI for values, with a specified timeout.
         *
         * @param timeout
         *            Number of milliseconds to wait for results before timing
         *            out. If {@link IEnumWbemClassObject#WBEM_INFINITE} (-1),
         *            will always wait for results. If a timeout occurs, throws
         *            a {@link TimeoutException}.
         *
         * @return a WmiResult object containing the query results, wrapping an
         *         EnumMap
         *
         * @throws TimeoutException
         *             if the query times out before completion
         */
        public WmiResult<T> execute(int timeout) throws TimeoutException {
            // Idiot check
            if (getPropertyEnum().getEnumConstants().length < 1) {
                throw new IllegalArgumentException("The query's property enum has no values.");
            }

            // Connect to the server
            IWbemServices svc = connectServer(getNameSpace());

            // Send query
            try {
                IEnumWbemClassObject enumerator = selectProperties(svc, this);

                try {
                    return enumerateProperties(enumerator, getPropertyEnum(), timeout);
                } finally {
                    // Cleanup
                    enumerator.Release();
                }
            } finally {
                // Cleanup
                svc.Release();

View on GitHub (pinned to d036ad9781)

Solutions

  1. Define at least one enum constant matching a WMI query property you select.
  2. Check that your WQL SELECT clause and the enum constants correspond.
  3. Validate the enum at startup if queries are configured dynamically.
  4. Catch IllegalArgumentException around execute() when query definitions come from external input.

Example fix

// before
enum Result {} // empty
new WbemcliUtil.WmiQuery<>("ROOT\\CIMV2", "SELECT * FROM Win32_OperatingSystem", Result.class).execute();
// after
enum Result { CAPTION, VERSION }
new WbemcliUtil.WmiQuery<>("ROOT\\CIMV2", "SELECT Caption,Version FROM Win32_OperatingSystem", Result.class).execute();
Defensive patterns

Strategy: validation

Validate before calling

if (query.getPropertyEnum().getEnumConstants().length == 0) {
    throw new IllegalStateException("Query enum must define at least one property");
}

Try / catch

try {
    query.execute();
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("no values")) { /* fix enum definition */ }
}

Prevention

When it happens

Trigger: Creating a WmiQuery<T> where T is an enum with zero constants, then calling execute()/execute(timeout).

Common situations: Defining an empty enum placeholder while scaffolding code; generating the enum from a template or WMI class metadata that produced no fields; deleting all enum constants during refactoring.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of java-native-access/jna@d036ad9781 (2026-09-12). Data as JSON: /api/errors/5529b07476a22f78. Report an issue: GitHub.