Skip to content

Fix NPE during project group creation caused by ergonomics#8171

Merged
mbien merged 1 commit intoapache:masterfrom
mbien:fix-ergonomics-pg-npe
Jan 23, 2025
Merged

Fix NPE during project group creation caused by ergonomics#8171
mbien merged 1 commit intoapache:masterfrom
mbien:fix-ergonomics-pg-npe

Conversation

@mbien
Copy link
Copy Markdown
Member

@mbien mbien commented Jan 19, 2025

Projects can change class type due to ergonomics. Hashcode/equals matching problems make storage in sets/maps problematic.

Unbox "FeatureNonProject" since

public boolean equals(Object obj) {
if (obj instanceof Project) {
return ((Project)obj).getProjectDirectory().equals(getProjectDirectory());
}
return false;
}
@Override
public int hashCode() {
return getProjectDirectory().hashCode();
}

isn't compatible with

@Override
public int hashCode() {
return getPOMFile().hashCode() * 13;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Project) {
NbMavenProjectImpl impl;
if (obj instanceof NbMavenProjectImpl) {
impl = ((NbMavenProjectImpl) obj);
} else {
impl = ((Project) obj).getLookup().lookup(NbMavenProjectImpl.class);
}
if (impl != null) {
return getPOMFile().equals(impl.getPOMFile());
}
}
return false;
}

discovered while implementing #8164

fixes #6011, https://issues.apache.org/jira/browse/NETBEANS-2167 and https://bz.apache.org/netbeans/show_bug.cgi?id=235897

reproducer:

  1. clean NB config, don't import on start
  2. open existing maven project
  3. open any project file
  4. create new project group -> NPE

@mbien mbien added Editor ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Jan 19, 2025
@mbien mbien added this to the NB25 milestone Jan 19, 2025
@mbien mbien marked this pull request as draft January 19, 2025 23:49
@mbien
Copy link
Copy Markdown
Member Author

mbien commented Jan 19, 2025

something isn't working correctly. tabs close now when a pg is created for a project loaded by ergonomics. i swear this worked when i tested it :(

edit: updated the impl to unbox the Project earlier. Might have hit a hash collision which caused the Set to delegate to equals?

@mbien mbien force-pushed the fix-ergonomics-pg-npe branch from 2811b50 to 8ef6439 Compare January 20, 2025 02:10
@mbien mbien force-pushed the fix-ergonomics-pg-npe branch from 8ef6439 to 8cff047 Compare January 20, 2025 17:12
@mbien mbien marked this pull request as ready for review January 20, 2025 17:15
Projects can change class type due to ergonomics. Hashcode/equals
matching problems make storage in sets/maps problematic.

 - try to unbox the project before use.
 - simplify code paths affected by this
@mbien mbien force-pushed the fix-ergonomics-pg-npe branch from 8cff047 to 99ea64d Compare January 20, 2025 18:16
Copy link
Copy Markdown
Contributor

@eirikbakke eirikbakke left a comment

Choose a reason for hiding this comment

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

Looks good, thank you! (Would be good to do just a final manual test with the latest version of the code before merging.)

@mbien
Copy link
Copy Markdown
Member Author

mbien commented Jan 23, 2025

planning to merge this today (tomorrow is freeze)

@mbien mbien merged commit 94c0b0f into apache:master Jan 23, 2025
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) Editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

changing project group shows an exception in the log

2 participants