Repository navigation
Fix NPE when saving a project with an empty text-equals filter value - #3236
Conversation
EqualStringFilter's pattern field had no default, so a filter added to the panel but left empty stayed null until the user typed something. Saving the project then serialized that null straight into the XML writer's writeCharacters call, which throws on some StAX implementations. Default pattern to "" like the sibling EgoFilter does, and guard writeParameter so a null serialized value never reaches the writer regardless of which filter produced it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
The fix looks correct and minimal for the reported crash ( However, there's an identical unguarded call site that this PR doesn't touch: for (Entry<LayoutPropertyKey, Object> entry : savedProperties.entrySet()) {
if (entry.getValue() != null) {
...
writer.writeCharacters(Serialization.getValueAsText(entry.getValue()));
...The Unlike |
Description
When a user adds an "Attributes > Equal" filter for a text column via the Filters panel but never types a value into it before saving the project, the save silently produces broken output today — and on some XML stream implementations, throws an exception in the process.
The root cause is in
EqualStringFilter(modules/FiltersPlugin/src/main/java/org/gephi/filters/plugin/attribute/AttributeEqualBuilder.java): itspatternfield has no initializer and is never set unless the user callssetPattern(...). Sibling filters likeEgoBuilder.EgoFilterdefault their equivalent field to"", but this one doesn't, sopatternstaysnullfor a freshly added, untouched filter.When the project is saved,
FilterModelPersistenceProvider.writeParameter(modules/FiltersImpl/src/main/java/org/gephi/filters/FilterModelPersistenceProvider.java:168) serializes every filter property by callingSerialization.toText(value, type)and passing the result straight towriter.writeCharacters(...).Serialization.toTextreturnsnullfor anullinput value by design, sowriteCharacters(null)gets called. Depending on theXMLStreamWriterimplementation in use, that throws an NPE — this is what shows up in Sentry as GEPHI-5SY.The fix is two-fold and minimal:
writeParameternow guards the serialized text and writes""instead ofnull, so no filter property (not just this one) can ever push a null into the XML writer.EqualStringFilter.patternnow defaults to"", matchingEgoFilter, so the null case doesn't occur in the first place for this filter.https://gephi.sentry.io/issues/GEPHI-5SY
Checklist
Added tests?
Added
AttributeEqualBuilderTest.testEqualStringFilterDefaultPatternIsNotNull(FiltersPlugin), which fails before the fix (asserts the filter built viaAttributeEqualBuildernever has a null pattern), and a persistence round-trip test inPersistenceProviderTestcovering anEqualStringFilterleft without a pattern.Added to documentation?