Repository navigation
Fix NullPointerException in regex-based attribute equal filter with empty pattern - #3324
Merged
Merged
Conversation
EqualStringFilter.evaluate() calls regex.matcher(...) whenever useRegex is true, but the regex field is only ever assigned inside setPattern(). A filter left in its default state (pattern="", regex=null) with useRegex set to true throws a NullPointerException instead of matching. This happens both from the UI, when setUseRegex(true) is called without setPattern() ever being called, and when reloading a saved project: FilterModelPersistenceProvider.readQuery() only calls setValue() on a persisted parameter when its serialized text is non-empty, so a pattern of "" is never replayed through setPattern() on load, leaving regex null even though useRegex=true is restored. Initialize regex from the default pattern value at field declaration so it can never be null, keeping the empty-pattern regex semantics consistent with the non-regex branch (pattern.equals(valString)), which already matches only empty-string values for pattern="". Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a
NullPointerExceptioninEqualStringFilter.evaluate()affecting 4 users across 9 events in production.Mechanism:
EqualStringFilter(modules/FiltersPlugin/src/main/java/org/gephi/filters/plugin/attribute/AttributeEqualBuilder.java:144-200) declaresprivate Pattern regex;with no initializer. The only place that ever assigns it issetPattern(String)(line 189-192), which doesthis.regex = Pattern.compile(pattern);.evaluate()(line 165-179) callsregex.matcher(valString).matches()at line 173 wheneveruseRegexistrue, with no null check.regexstays null whileuseRegexistruein two situations:pattern = "",regex = nullby default) hassetUseRegex(true)called on it withoutsetPattern(...)ever being called first — e.g. directly from the filter UI.FilterModelPersistenceProvider.readQuery()(modules/FiltersImpl/src/main/java/org/gephi/filters/FilterModelPersistenceProvider.java:325) only callsproperty.setValue(value)if (property != null && textBuffer.length() > 0). When the filter'spatternwas""at save time, the persisted<parameter>element forpatternis empty text, sosetPattern()is skipped entirely on load — while theuseRegex=trueparameter (non-empty text"true") is replayed viasetUseRegex(true). The filter comes back from persistence withuseRegex=trueandregexstill null.Either path leads straight into
FilterProcessor.processNodeFilter()(modules/FiltersImpl/src/main/java/org/gephi/filters/FilterProcessor.java:155) callingnodeFilter.evaluate(graph, n)on every node, which throws on the first node with a non-null attribute value.Stack trace (GEPHI-6CG)
Fix: initialize
regexfrom the defaultpatternvalue at field declaration (private Pattern regex = Pattern.compile(pattern);), relying onpattern's initializer running first since it's declared aboveregex. This guaranteesregexis never null regardless of how the filter reaches its default/deserialized state, instead of depending entirely onsetPattern()having been called at some point. This keeps the regex-empty-pattern semantics consistent with the non-regex branch: an empty pattern matches only empty-string attribute values ("".matches("")istrue, same as"".equals(valString)), rather than silently treating the filter as always-match or never-match.Sentry: https://gephi.sentry.io/issues/GEPHI-6CG
Checklist
Added tests?
Added regression tests to
AttributeEqualBuilderTest: one constructs a filter and callssetUseRegex(true)without ever callingsetPattern(...), then evaluates it; the other callssetPattern("")explicitly (covering the persistence-reload path) beforesetUseRegex(true)and evaluates. Both previously threw the NPE and now correctly returnfalsefor a non-empty attribute value.Added to documentation?
🤖 Generated with Claude Code