Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Settings persistence does not work for inner-class hints #7077

Merged
merged 2 commits into from
Feb 27, 2024

Conversation

mbien
Copy link
Member

@mbien mbien commented Feb 17, 2024

Settings persistence does not like keys with $ signs in them. Two hints (bugs.Unbalanced$Array and $Collection) were implemented via annotated inner classes and can't be disabled by the user since the FQN is used as key/id by default.

Easiest fix seems to be to change the default id generation a bit and replace '$' with '_'. I am sure this could be also implemented somewhere later in the logic but I couldn't find the reason why the preference entry is quietly ignored, so I went for the easy option.

However a better option might be to encode the $ in AuxiliaryConfigBasedPreferencesProvider which is already encoding
other chars.

how to replicate:

  • new maven project
  • open project settings -> hints -> use project specific options
  • disable one of the "unbalanced" hints -> ok
  • check if the config is written to nb-configuration.xml
  • check if the hint is still disabled in project properties

@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) hints ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Feb 17, 2024
@mbien mbien added this to the NB22 milestone Feb 17, 2024
@mbien mbien requested a review from lahodaj February 17, 2024 19:08
@matthiasblaesing
Copy link
Contributor

What happens in the problematic cases? This sounds like the problem lies deeper and should be fixed at the root.

Settings persistence does not like keys with $ signs in them. Two hints
(bugs.Unbalanced$Array and $Collection) were implemented via annotated
inner classes and can't be disabled by the user since the FQN is used
as key/id by default.

This could be fixed by changing the hint id itself, or by changing
the default id generator code.

However a better option might be to encode the $ in
AuxiliaryConfigBasedPreferencesProvider which is already encoding
other chars.
@mbien mbien added the ci:all-tests [ci] enable all tests label Feb 18, 2024
@mbien
Copy link
Member Author

mbien commented Feb 18, 2024

you are right. I couldn't find it yesterday, but I did find it today. Enabling all tests since this would be in the project api itself.

btw invalid keys will produce a warning:

WARNING [org.netbeans.modules.maven.MavenProjectPropsImpl]: #200901: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified. from org-netbeans-spi-editor-hints-projects.text.x-java.org_2e_netbeans_2e_modules_2e_java_2e_hints_2e_bugs_2e_Unbalanced$Collection.enabled

here:

try {
enEl = el.getOwnerDocument().createElementNS(NAMESPACE, key);
} catch (DOMException x) {
LOG.log(Level.WARNING, "#200901: {0} from {1}", new Object[] {x.getMessage(), key});
continue;
}

@mbien mbien force-pushed the fix-inner-class-hints branch from 0167cc8 to 8107f06 Compare February 18, 2024 19:02
@mbien mbien removed the ci:all-tests [ci] enable all tests label Feb 27, 2024
Copy link
Contributor

@lkishalmi lkishalmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable.

@mbien mbien merged commit da1da73 into apache:master Feb 27, 2024
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) Code cleanup hints Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants