Fix NPE when copying a namespace set with a root sub-namespace#3881
Merged
Conversation
NamespaceSet.getParent() built its map by putting each namespace's parent (b.parent()) as the value. A sub-namespace without an enclosing layer has no parent, so b.parent() is null and the map ended up holding a null value. copy() (and copyWithParent()/getCompression()) then call v.copy() on it and throw a NullPointerException. This surfaced when a splitting taclet is applied interactively: for the second and later goals, Goal.adaptNamespacesNewGoals does localNamespaces.getParent().copy().copyWithParent(), which hit the null. The regression came in with generalizing NamespaceSet onto a Map (e8bc655) — the previous fixed typed fields could not carry a null entry. getParent() now substitutes an empty namespace for a missing parent layer, so the "map holds no null values" invariant the other map operations rely on keeps holding. Adds a regression test. Created with AI tooling support
unp1
marked this pull request as ready for review
July 1, 2026 19:05
unp1
enabled auto-merge
July 1, 2026 19:36
wadoon
approved these changes
Jul 2, 2026
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.
Intended Change
Applying a splitting taclet interactively (e.g. dragging a formula into an
instantiation field and pressing Apply) could crash with a
NullPointerException:Root cause.
NamespaceSet.getParent()built its map by storing eachnamespace's parent as the value:
A sub-namespace without an enclosing layer has no parent, so
b.parent()isnulland the resulting map holds anullvalue.copy()(and likewisecopyWithParent()/getCompression()) then callv.copy()on that value andthrow. For the second and later goals of a splitting rule,
Goal.adaptNamespacesNewGoalsdoeslocalNamespaces.getParent().copy().copyWithParent(), which is where it blew up.Fix.
getParent()now substitutes an empty namespace for a missing parentlayer, so the "the map holds no null values" invariant that the other map
operations rely on keeps holding.
Type of pull request
Ensuring quality
NamespaceSetTest.getParentOfRootNamespacesIsCopyable, which fails with the original NPE and passes with the fix).:key.corecompiles and passes spotless; the new regression test is green (and verified red without the fix).Additional information and contact(s)
Created with AI tooling support
The contributions within this pull request are licensed under GPLv2 (only) for inclusion in KeY.