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

WorkbookEditorsHandler: Fix NPE in case name is null #1286

Merged

Conversation

sratz
Copy link
Member

@sratz sratz commented Nov 7, 2023

Fixes #1275.

(Regression was introduced in 03277d3)

Copy link
Contributor

github-actions bot commented Nov 7, 2023

Test Results

     899 files   -        1       899 suites   - 1   42m 13s ⏱️ - 9m 39s
  7 468 tests ±       0    7 314 ✔️ +       2  153 💤 ±    0  1  - 2 
21 977 runs   - 1 576  21 587 ✔️  - 1 454  389 💤  - 120  1  - 2 

For more details on these failures, see this check.

Results for commit b5aad0e. ± Comparison against base commit 4c5fccc.

♻️ This comment has been updated with latest results.

@@ -162,10 +164,10 @@ private List<EditorReference> getParts(WorkbenchPage page) {
*/
private Map<EditorReference, String> generateColumnLabelTexts(List<EditorReference> editorReferences) {
Map<EditorReference, String> editorReferenceLabelTexts = new HashMap<>(editorReferences.size());
Map<String, List<EditorReference>> collisionsMap = editorReferences.stream()
.collect(Collectors.groupingBy(r -> r.getName()));
Map<Optional<String>, List<EditorReference>> collisionsMap = editorReferences.stream()
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe one should filter out null names altogether?

Copy link
Member Author

Choose a reason for hiding this comment

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

Then they would disappear from Ctrl-E?

I guess keeping them is the safest approach for now and just fix the regression introduced by 03277d3 .

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about using Objects.requireNonNullOrElse(r.getName(), "N/A"); if the only problem is that name is null (whatever that the should mean to the user).

Copy link
Member Author

@sratz sratz Nov 7, 2023

Choose a reason for hiding this comment

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

I think I have a better solution:

The actual intended text to be used in Ctrl-E (if unique), is ref.getTitle(),

which is already null-safe (returns "" in that case):

@Override
public String getTitle() {
String label = Util.safeString(getModel().getLocalizedLabel());
if (label.isEmpty()) {
if (input == null) {
if (descriptor != null) {
return descriptor.getLabel();
}
} else {
return Util.safeString(input.getName());
}
}
return label;
}

But in 03277d3 I have inadvertently used getName() to populate the collisionMap.

It should simply also use getTitle().

@sratz sratz force-pushed the WorkbookEditorsHandler-npe branch 3 times, most recently from 67cfb45 to a88b209 Compare November 8, 2023 09:34
@sratz
Copy link
Member Author

sratz commented Nov 8, 2023

Any objections to merge like this? (I don't know why the build is failing, but it's definitely unrelated).

Copy link
Contributor

@laeubi laeubi 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

Copy link
Member

@iloveeclipse iloveeclipse left a comment

Choose a reason for hiding this comment

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

We can't merge, API tools are broken. @laeubi : please take a look.

See https://ci.eclipse.org/platform/job/eclipse.platform.ui/job/PR-1286/4/console

09:45:32.437 [ERROR] Failed to execute goal org.eclipse.tycho:tycho-apitools-plugin:4.0.4:verify (verify) on project org.eclipse.ui.workbench: There are API errors:
09:45:32.437 [ERROR] Eclipse UI/org/eclipse/ui/AbstractSourceProvider.java:31 The type org.eclipse.ui.AbstractSourceProvider has been removed from org.eclipse.ui.workbench_3.131.0
09:45:32.438 [ERROR] Eclipse UI/org/eclipse/ui/ActiveShellExpression.java:32 The type org.eclipse.ui.ActiveShellExpression has been removed from org.eclipse.ui.workbench_3.131.0
09:45:32.438 [ERROR] Eclipse UI/org/eclipse/ui/BasicWorkingSetElementAdapter.java:58 The type org.eclipse.ui.BasicWorkingSetElementAdapter has been removed from org.eclipse.ui.workbench_3.131.0
09:45:32.438 [ERROR] Eclipse UI/org/eclipse/ui/ExtensionFactory.java:46 The type org.eclipse.ui.ExtensionFactory has been removed from org.eclipse.ui.workbench_3.131.0
09:45:32.438 [ERROR] Eclipse UI/org/eclipse/ui/IActionBars.java:66 The type org.eclipse.ui.IActionBars has been removed from org.eclipse.ui.workbench_3.131.0
09:45:32.438 [ERROR] Eclipse UI/org/eclipse/ui/IActionBars2.java:24 The type org.eclipse.ui.IActionBars2 has been removed from org.eclipse.ui.workbench_3.131.0
09:45:32.438 [ERROR] Eclipse UI/org/eclipse/ui/IActionDelegate.java:53 The type org.eclipse.ui.IActionDelegate has been removed from org.eclipse.ui.workbench_3.131.0
09:45:32.438 [ERROR] Eclipse UI/org/eclipse/ui/IActionDelegate2.java:42 The type org.eclipse.ui.IActionDelegate2 has been removed from org.eclipse.ui.workbench_3.131.0
09:45:32.438 [ERROR] Eclipse UI/org/eclipse/ui/IActionDelegateWithEvent.java:34 The type org.eclipse.ui.IActionDelegateWithEvent has been removed from org.eclipse.ui.workbench_3.131.0
09:45:32.438 [ERROR] Eclipse UI/org/eclipse/ui/IActionFilter.java:52 The type org.eclipse.ui.IActionFilter has been removed from org.eclipse.ui.workbench_3.131.0
09:45:32.438 [ERROR] Eclipse UI/org/eclipse/ui/IAggregateWorkingSet.java:30 The type org.eclipse.ui.IAggregateWorkingSet has been removed from org.eclipse.ui.workbench_3.131.0
09:45:32.438 [ERROR] Eclipse UI/org/eclipse/ui/IContainmentAdapter.java:22 The type 

...

@jukzi
Copy link
Contributor

jukzi commented Nov 8, 2023

We can't merge, API tools are broken. @laeubi : please take a look.

see eclipse-equinox/p2#382 (comment)
currently it helps to add the default 'output.. = bin/' to build.properties.

@@ -163,7 +163,7 @@ private List<EditorReference> getParts(WorkbenchPage page) {
private Map<EditorReference, String> generateColumnLabelTexts(List<EditorReference> editorReferences) {
Map<EditorReference, String> editorReferenceLabelTexts = new HashMap<>(editorReferences.size());
Map<String, List<EditorReference>> collisionsMap = editorReferences.stream()
.collect(Collectors.groupingBy(r -> r.getName()));
.collect(Collectors.groupingBy(r -> r.getTitle()));
Copy link
Contributor

Choose a reason for hiding this comment

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

How about replacing null with empty string?

Copy link
Member Author

Choose a reason for hiding this comment

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

getTitle() already does that and does not return null

Copy link
Contributor

Choose a reason for hiding this comment

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

that can return descriptor.getLabel() that can return configurationElement.getAttribute(IWorkbenchRegistryConstants.ATT_NAME); that can return null

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I have added another Util.safeString() guard around it.

@iloveeclipse
Copy link
Member

see eclipse-equinox/p2#382 (comment) currently it helps to add the default 'output.. = bin/' to build.properties.

  1. The problem is still there. Please fix that (even if it is not introduced by you).
  2. M3 is currently in the process to be declared. No merges are expected before that.
  3. Once M3 is officially declared, we could try to merge (assuming 1) is solved and build is green), but we will need a positive vote from a project lead to do that.

@iloveeclipse iloveeclipse added this to the 4.30 RC1 milestone Nov 9, 2023
@jukzi
Copy link
Contributor

jukzi commented Nov 9, 2023

  1. The problem is still there. Please fix that (even if it is not introduced by you).

it's tychos problem eclipse-tycho/tycho#3019

Regression was introduced in 03277d3,
where getTitle() was accidentally changed to getName().

Revert that back to getTitle().

getTitle() is already null-safe in most cases, but to be 100% safe,
guard it using Util.safeString() again.

Fixes eclipse-platform#1275.
@sratz
Copy link
Member Author

sratz commented Nov 14, 2023

@iloveeclipse: Any objections to merge for RC1?

Copy link
Member

@iloveeclipse iloveeclipse left a comment

Choose a reason for hiding this comment

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

LGTM

@iloveeclipse iloveeclipse merged commit b72dc9b into eclipse-platform:master Nov 14, 2023
13 of 16 checks passed
@laeubi
Copy link
Contributor

laeubi commented Nov 14, 2023

@vogella @merks we need a PL/PMC approval for RC1 I think its worth to be considered.
@iloveeclipse build is green now except flaky VirtualTableViewerTest what I think is not affected by this change.

@sratz sratz deleted the WorkbookEditorsHandler-npe branch November 14, 2023 10:01
@merks
Copy link
Contributor

merks commented Nov 14, 2023

PMC +1

I do generally trust that folks will use their discretion to fix things that really ought to be fixed and to avoid changing things that are risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quick switch editor (Cmd+E) throws NPE
6 participants