You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by "tmvlad (via GitHub)" <gi...@apache.org> on 2026/03/06 09:09:53 UTC
[PR] OAK-12125: throw IllegalStateException for property index missing propertyNames [jackrabbit-oak]
tmvlad opened a new pull request, #2784:
URL: https://github.com/apache/jackrabbit-oak/pull/2784
## Summary
A property index definition with `type=property` but missing the required `propertyNames` property caused a `NullPointerException` in `PropertyIndexEditor` that was not caught by `IndexUpdate`, breaking the entire async indexing cycle for all indexes.
- Add a null check in `PropertyIndexEditor` constructor and throw an `IllegalStateException` with a clear message when `propertyNames` is absent
- `IndexUpdate.collectIndexEditors()` already catches `IllegalStateException` to gracefully skip bad index definitions and log an error, so async indexing continues unaffected
- Add regression test `missingPropertyNamesDoesNotBreakIndexing` in `PropertyIndexTest`
## Test plan
- [ ] `mvn test -pl oak-core -Dtest=PropertyIndexTest#missingPropertyNamesDoesNotBreakIndexing`
- [ ] `mvn test -pl oak-core -Dtest=PropertyIndexTest`
🤖 Generated with [Claude Code](https://claude.ai/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-12125: Use sentinel when propertyNames is null [jackrabbit-oak]
Posted by "thomasmueller (via GitHub)" <gi...@apache.org>.
thomasmueller commented on code in PR #2784:
URL: https://github.com/apache/jackrabbit-oak/pull/2784#discussion_r3332594340
##########
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java:
##########
@@ -132,7 +138,18 @@ public PropertyIndexEditor(NodeBuilder definition, NodeState root,
// get property names
PropertyState names = definition.getProperty(PROPERTY_NAMES);
- if (names.count() == 1) {
+ if (names == null && Boolean.parseBoolean(System.getProperty(FT_GRANITE_63829))) {
Review Comment:
So far we throw a NullPointerException. We could argue a feature toggle is not needed in this case. But let's add one anyway (possibly NPE is better than not throwing a NPE, for some weird reason).
Please use a feature toggle like other we use, see oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/toggle/FeatureToggle.java
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-12125: Use sentinel when propertyNames is null [jackrabbit-oak]
Posted by "thomasmueller (via GitHub)" <gi...@apache.org>.
thomasmueller commented on code in PR #2784:
URL: https://github.com/apache/jackrabbit-oak/pull/2784#discussion_r3334123559
##########
oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java:
##########
@@ -1187,4 +1190,156 @@ private String getCommitPath(String changeNodeName) {
return PathUtils.concat(path, changeNodeName);
}
}
+
+ /**
+ * @see <a href="https://issues.apache.org/jira/browse/OAK-12125">OAK-12125</a>
+ *
+ * With no Feature wired into the provider (the default), a property index
+ * definition missing the required 'propertyNames' must NPE out of the editor
+ * constructor. IndexUpdate catches IllegalStateException but NOT NullPointerException,
+ * so the NPE propagates and breaks the indexing cycle. This pins the
+ * "default OFF = pre-PR behavior" contract.
+ */
+ @Test
+ public void missingPropertyNames_toggleOff_breaksIndexing() throws Exception {
+ NodeState root = INITIAL_CONTENT;
+ NodeBuilder builder = root.builder();
+
+ NodeBuilder invalidIndex = builder.child(INDEX_DEFINITIONS_NAME).child("invalidIndex_off");
+ invalidIndex.setProperty(JCR_PRIMARYTYPE,
+ IndexConstants.INDEX_DEFINITIONS_NODE_TYPE, Type.NAME);
+ invalidIndex.setProperty(IndexConstants.TYPE_PROPERTY_NAME,
+ PropertyIndexEditorProvider.TYPE);
+
+ NodeState before = builder.getNodeState();
+ builder.child("content").setProperty("foo", "bar");
+ NodeState after = builder.getNodeState();
+
+ try {
+ HOOK.processCommit(before, after, CommitInfo.EMPTY);
+ fail("Expected NullPointerException to propagate from the indexing cycle");
+ } catch (NullPointerException expected) {
+ // success path: NPE bubbled directly
+ } catch (Exception other) {
+ // Some Oak commit-hook layers wrap exceptions; accept NPE anywhere in cause chain
+ Throwable cause = other;
+ boolean foundNpe = false;
+ while (cause != null) {
+ if (cause instanceof NullPointerException) {
+ foundNpe = true;
+ break;
+ }
+ cause = cause.getCause();
+ }
+ assertTrue("Expected NullPointerException in the cause chain, got: " + other, foundNpe);
+ }
+ }
+
+ /**
+ * @see <a href="https://issues.apache.org/jira/browse/OAK-12125">OAK-12125</a>
+ *
+ * With an enabled Feature wired into the provider, a missing 'propertyNames'
+ * must NOT throw. Instead the editor falls back to a sentinel, logs one WARN
+ * naming the misconfigured index path, and lets the indexing cycle complete
+ * so the valid sibling index still works.
+ */
+ @Test
+ public void missingPropertyNames_toggleOn_logsWarnAndContinues() throws Exception {
+ EditorHook hook = hookWithFeatureEnabled(true);
+ LogCustomizer customLogs = LogCustomizer
+ .forLogger(PropertyIndexEditor.class.getName()).enable(Level.WARN).create();
+ try {
+ customLogs.starting();
+
+ NodeState root = INITIAL_CONTENT;
+ NodeBuilder builder = root.builder();
+
+ createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo",
+ true, false, Set.of("foo"), null);
+
+ NodeBuilder invalidIndex = builder.child(INDEX_DEFINITIONS_NAME).child("invalidIndex_on");
+ invalidIndex.setProperty(JCR_PRIMARYTYPE,
+ IndexConstants.INDEX_DEFINITIONS_NODE_TYPE, Type.NAME);
+ invalidIndex.setProperty(IndexConstants.TYPE_PROPERTY_NAME,
+ PropertyIndexEditorProvider.TYPE);
+
+ NodeState before = builder.getNodeState();
+ builder.child("content").setProperty("foo", "bar");
+ NodeState after = builder.getNodeState();
+
+ NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
+
+ assertTrue("Expected a WARN message naming the invalid index path",
+ customLogs.getLogs().stream().anyMatch(
+ msg -> msg.contains("invalidIndex_on") && msg.contains(IndexConstants.PROPERTY_NAMES)));
+
+ FilterImpl f = createFilter(indexed, NT_BASE);
+ PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
+ assertEquals(Set.of("content"), find(lookup, "foo", "bar", f));
+ } finally {
+ customLogs.finished();
+ }
+ }
+
+ /**
+ * @see <a href="https://issues.apache.org/jira/browse/OAK-12125">OAK-12125</a>
+ *
+ * With the Feature enabled and the same invalid index hit twice, exactly one
+ * WARN must be emitted for that index path. Uses a unique index node name
+ * ("invalidIndex_dedup") so the JVM-wide dedup set doesn't get poisoned by
+ * earlier tests in the suite.
+ */
+ @Test
+ public void missingPropertyNames_toggleOn_warnLoggedOncePerIndexPath() throws Exception {
+ EditorHook hook = hookWithFeatureEnabled(true);
+ LogCustomizer customLogs = LogCustomizer
+ .forLogger(PropertyIndexEditor.class.getName()).enable(Level.WARN).create();
+ try {
+ customLogs.starting();
+
+ NodeState root = INITIAL_CONTENT;
+ NodeBuilder builder = root.builder();
+
+ NodeBuilder invalidIndex = builder.child(INDEX_DEFINITIONS_NAME).child("invalidIndex_dedup");
+ invalidIndex.setProperty(JCR_PRIMARYTYPE,
+ IndexConstants.INDEX_DEFINITIONS_NODE_TYPE, Type.NAME);
+ invalidIndex.setProperty(IndexConstants.TYPE_PROPERTY_NAME,
+ PropertyIndexEditorProvider.TYPE);
+
+ NodeState before = builder.getNodeState();
+ builder.child("content_a").setProperty("foo", "bar");
+ NodeState after1 = builder.getNodeState();
+ hook.processCommit(before, after1, CommitInfo.EMPTY);
+
+ builder.child("content_b").setProperty("foo", "baz");
+ NodeState after2 = builder.getNodeState();
+ hook.processCommit(after1, after2, CommitInfo.EMPTY);
+
+ long warnsForThisIndex = customLogs.getLogs().stream()
+ .filter(msg -> msg.contains("invalidIndex_dedup"))
+ .count();
+ assertEquals("Expected exactly one WARN for invalidIndex_dedup across two cycles, got: "
+ + customLogs.getLogs(), 1, warnsForThisIndex);
+ } finally {
+ customLogs.finished();
+ }
+ }
+
+ private static EditorHook hookWithFeatureEnabled(boolean enabled) {
+ Feature feature = Mockito.mock(Feature.class);
+ Mockito.when(feature.isEnabled()).thenReturn(enabled);
+ PropertyIndexEditorProvider provider = new PropertyIndexEditorProvider();
+ injectFeature(provider, feature);
+ return new EditorHook(new IndexUpdateProvider(provider));
+ }
+
+ private static void injectFeature(PropertyIndexEditorProvider provider, Feature feature) {
+ try {
+ Field f = PropertyIndexEditorProvider.class.getDeclaredField("feature");
+ f.setAccessible(true);
+ f.set(provider, feature);
Review Comment:
I think we should not use setAccessible
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-12125: Use sentinel when propertyNames is null [jackrabbit-oak]
Posted by "thomasmueller (via GitHub)" <gi...@apache.org>.
thomasmueller closed pull request #2784: OAK-12125: Use sentinel when propertyNames is null
URL: https://github.com/apache/jackrabbit-oak/pull/2784
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-12125: throw IllegalStateException for property index missing propertyNames [jackrabbit-oak]
Posted by "thomasmueller (via GitHub)" <gi...@apache.org>.
thomasmueller commented on code in PR #2784:
URL: https://github.com/apache/jackrabbit-oak/pull/2784#discussion_r3071405260
##########
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexEditor.java:
##########
@@ -132,7 +132,10 @@ public PropertyIndexEditor(NodeBuilder definition, NodeState root,
// get property names
PropertyState names = definition.getProperty(PROPERTY_NAMES);
- if (names.count() == 1) {
+ if (names == null) {
+ throw new IllegalStateException("Missing required property '" + PROPERTY_NAMES + "' in property index definition");
Review Comment:
So instead of a NPE we now get an IllegalStateException... It might currently resolve the problem, but I think it is not a good solution, because still an exception is thrown. There is a performance overhead in throwing an exception, but more importantly exception handing is not part of the API, and so changes in the future might break this logic. Also, there is no logging.
An alternative solution would be:
* Use a default value if no propertyNames are set, eg. use the value "propertyNamesIsMissing". A property name that is so unlikely to occur in practice that there are no repositories with this property. (And if there are, then actually it wouldn't be a problem.)
* Log a warning, but only once. Only once such that the log file is not filled.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org