{"record":{"id":"1a4b8856f37f908c","repo":"quarkusio/quarkus","slug":"query-string-cannot-be-null","errorCode":null,"errorMessage":"Query string cannot be null","messagePattern":"Query string cannot be null","errorType":"exception","errorClass":"PanacheQueryException","httpStatus":null,"severity":"error","filePath":"extensions/panache/panache-hibernate-common/runtime/src/main/java/io/quarkus/panache/hibernate/common/runtime/PanacheJpaUtil.java","lineNumber":112,"sourceCode":"                || trimmedForAnalysis.startsWith(\"from \")) {\n            return query;\n        }\n        if (trimmedForAnalysis.startsWith(\"where \")) {\n            return \"FROM \" + getEntityName(entityClass) + \" \" + query;\n        }\n        if (trimmedForAnalysis.startsWith(\"order by \")) {\n            // ignore it\n            return \"FROM \" + getEntityName(entityClass);\n        }\n        if (trimmedForAnalysis.indexOf(' ') == -1 && trimmedForAnalysis.indexOf('=') == -1 && paramCount == 1) {\n            query += \" = ?1\";\n        }\n        return \"FROM \" + getEntityName(entityClass) + \" WHERE \" + query;\n    }\n\n    public static String createUpdateQuery(Class<?> entityClass, String query, int paramCount) {\n        if (query == null) {\n            throw new PanacheQueryException(\"Query string cannot be null\");\n        }\n\n        String trimmedForAnalysis = trimForAnalysis(query);\n        if (trimmedForAnalysis.isEmpty()) {\n            throw new PanacheQueryException(\"Query string cannot be empty\");\n        }\n\n        // backwards compat trying to be helpful, remove the from\n        if (trimmedForAnalysis.startsWith(\"update from\")) {\n            // find the original from and skip it\n            int index = query.toLowerCase(Locale.ROOT).indexOf(\"from\");\n            return \"update \" + query.substring(index + 4);\n        }\n        if (trimmedForAnalysis.startsWith(\"update \")) {\n            return query;\n        }\n        if (trimmedForAnalysis.startsWith(\"from \")) {\n            // find the original from and skip it","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/panache-hibernate-common/runtime/src/main/java/io/quarkus/panache/hibernate/common/runtime/PanacheJpaUtil.java#L94-L130","documentation":"PanacheJpaUtil.createUpdateQuery translates Panache update calls (e.g. update(\"name = ?1\", params)) into JPQL. A null query string cannot be interpreted — neither HQL nor a simple update fragment — so it throws PanacheQueryException before any analysis.","triggerScenarios":"Calling PanacheEntity.update(null, ...) / repository.update(null, ...) or a delete/update helper that forwards a null query, e.g. passing a variable that failed to initialize.","commonSituations":"Passing an unset String variable or a null result of a builder/optional chain; calling update() with no query where an overload without query was expected; refactoring that dropped the literal query.","solutions":["Pass a non-null query string, e.g. update(\"name = :name\", params) or update(\"from Person where name = :name\").","Null-check/require the query at your API boundary: Objects.requireNonNull(query).","If you intended to update the whole entity, use entity persist/merge APIs instead of an update query."],"exampleFix":"// before\nString q = condition != null ? \"name = :name\" : null;\npersonRepo.update(q, params); // NPE-style failure\n// after\nif (q != null) { personRepo.update(q, params); } else { /* handle empty update */ }","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(query, \"query must not be null\");\npersonRepo.update(query, params);","typeGuard":"String requireQuery(String q) {\n    if (q == null || q.isBlank()) throw new IllegalArgumentException(\"query required\");\n    return q;\n}","tryCatchPattern":"try {\n    PanacheJpaUtil.createUpdateQuery(entityClass, query, paramCount);\n} catch (PanacheQueryException e) {\n    // handle null/empty query: use default query or surface client error\n}","preventionTips":["Null-check query variables before Panache update/delete calls","Use literal query strings where possible","Don't forward Optional.get()-style nullable values into query APIs"],"tags":["panache","hibernate","jpa","null-argument","query"],"backgroundTag":"null-query-string","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}