-
Type: Improvement
-
Status: Open
-
Priority: Major
-
Resolution: Unresolved
-
Affects Version/s: 2021.x
-
Fix Version/s: None
-
Component/s: Audit
Scenario
Custom operation to query audit log entries where the document path matches (starts with) one of several path prefixes. NPE is caused by adding an OR-ed MultiExpression as a predicate.
Reproduction Steps
Create custom Java operation with following code snippet:
StringList paths = new StringList(); paths.add("/folder_1"); paths.add("/folder_2"); QueryBuilder builder = new AuditQueryBuilder(); builder = builder.predicate(Predicates.gt("id", 0)); builder = builder.and(Predicates.eq("category", "eventDocumentCategory")); List<Predicate> pathPredicates = paths.stream().map(path -> Predicates.startsWith("docPath", path)) .collect(Collectors.toList()); MultiExpression pathsPredicate = new MultiExpression(Operator.OR, pathPredicates); builder.and(pathsPredicate); AuditReader reader = Framework.getService(AuditReader.class); List<LogEntry> entries = reader.queryLogs(builder);
Check value of builder.predicate() (e.g.):
MultiExpression@193 "((id > 0) AND (category = 'eventDocumentCategory') AND ((docPath STARTSWITH '/folder_1') OR (docPath STARTSWITH '/folder_2')))"
Expected Result
entries is a list of LogEntry
Actual Result
reader.queryLogs(builder) throws a NullPointerException with stack trace (first few lines):
java.lang.NullPointerException at org.nuxeo.ecm.platform.audit.service.LogEntryProvider.lambda$queryLogs$1(LogEntryProvider.java:282) LogEntryProvider.java:282 at org.nuxeo.ecm.platform.audit.service.LogEntryProvider.queryLogs(LogEntryProvider.java:299) LogEntryProvider.java:299 at org.nuxeo.ecm.platform.audit.service.DefaultAuditBackend.lambda$queryLogs$12(DefaultAuditBackend.java:191) DefaultAuditBackend.java:191 at org.nuxeo.ecm.platform.audit.service.DefaultAuditBackend.lambda$apply$1(DefaultAuditBackend.java:134) DefaultAuditBackend.java:134 at org.nuxeo.ecm.core.persistence.PersistenceProvider.run(PersistenceProvider.java:166) PersistenceProvider.java:166
Notes
- This is a valid builder.predicate() value that does not throw a NPE:
MultiExpression@224 "((id > 0) AND (category = 'eventDocumentCategory') AND (docPath STARTSWITH '/folder_1'))"