Skip to content

Inline call to BundleHelper.getPlatformAdmin().getFactory()#1716

Merged
HannesWell merged 1 commit intoeclipse-pde:masterfrom
ptziegler:issue1714
Apr 8, 2025
Merged

Inline call to BundleHelper.getPlatformAdmin().getFactory()#1716
HannesWell merged 1 commit intoeclipse-pde:masterfrom
ptziegler:issue1714

Conversation

@ptziegler
Copy link
Copy Markdown
Contributor

@ptziegler ptziegler commented Apr 7, 2025

As a result of 14f66ae, it might happen
that the MinimalState is shut down, even though it was never started. In
such a case, the class is implicitly loaded while stopping the plug-in.

When loading this class, the "stateObjectFactory" is initialized using
the PlatformAdmin provided by the PDE Build bundle. If this bundle is
stopped before the PDE Core bundle, an exception is thrown because the
PlatformAdmin is no longer available.

The BundleHelper is already cached by the PDE Build plug-in and can
therefore be called directly, making the "stateObjectFactory" field
obsolete.

Closes #1714

Copy link
Copy Markdown
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.

Given that BundleHelper.getPlatformAdmin().getFactory() is already cached and we only have three call sites I wonder if it would not be better to replace calls directly with

BundleHelper.getPlatformAdmin().getFactory()

as in the suggestions.


protected MinimalState(MinimalState state) {
this.fState = stateObjectFactory.createState(state.fState);
this.fState = SingletonHolder.STATE_OBJECT_FACTORY.createState(state.fState);
Copy link
Copy Markdown
Contributor

@laeubi laeubi Apr 7, 2025

Choose a reason for hiding this comment

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

Suggested change
this.fState = SingletonHolder.STATE_OBJECT_FACTORY.createState(state.fState);
this.factory = BundleHelper.getPlatformAdmin().getFactory();
this.fState = factory.createState(state.fState);

Comment thread ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/MinimalState.java Outdated
Comment thread ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEState.java Outdated
Comment thread ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/MinimalState.java Outdated
As a result of 14f66ae, it might happen
that the MinimalState is shut down, even though it was never started. In
such a case, the class is implicitly loaded while stopping the plug-in.

When loading this class, the "stateObjectFactory" is initialized using
the PlatformAdmin provided by the PDE Build bundle. If this bundle is
stopped before the PDE Core bundle, an exception is thrown because the
PlatformAdmin is no longer available.

The BundleHelper is already cached by the PDE Build plug-in and can
therefore be called directly, making the "stateObjectFactory" field
obsolete.

Closes eclipse-pde#1714
@ptziegler ptziegler changed the title Use Initialize-on-demand holder idiom for StateObjectFactory Inline call to BundleHelper.getPlatformAdmin().getFactory() Apr 7, 2025
@ptziegler
Copy link
Copy Markdown
Contributor Author

Given that BundleHelper.getPlatformAdmin().getFactory() is already cached and we only have three call sites I wonder if it would not be better to replace calls directly with

BundleHelper.getPlatformAdmin().getFactory()

as in the suggestions.

That makes sense. The singleton in the BundleHelper is implicitly synchronized by the Bundle.start() and Bundle.stop() methods and removing excessive indirections is always a good thing.

I've applied your changes and updated the commit title/description.

Copy link
Copy Markdown
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 to me, factory can become a (protected) instance field then we even have only one reference at all (but not a static one), but even with this for I don't think we will see any issues.
Only "addBundle" is something that might be called more often here.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2025

Test Results

   285 files  ±0     285 suites  ±0   50m 33s ⏱️ +11s
 3 608 tests ±0   3 532 ✅ ±0   76 💤 ±0  0 ❌ ±0 
11 016 runs  ±0  10 785 ✅ ±0  231 💤 ±0  0 ❌ ±0 

Results for commit efe4281. ± Comparison against base commit 14f66ae.

@ptziegler
Copy link
Copy Markdown
Contributor Author

ptziegler commented Apr 7, 2025

The four new compiler warnings are about the parameters of the RequiredPackageVersionRange record, which is unrelated to this PR and from my perspective also wrong.

@laeubi
Copy link
Copy Markdown
Contributor

laeubi commented Apr 7, 2025

The four new compiler warnings are about the parameters of the RequiredPackageVersionRange record, which is unrelated to this PR and from my perspective also wrong.

I get the same warning in the IDE, seems an issue of JDT, should we keep this PR as a reference for now?

@laeubi
Copy link
Copy Markdown
Contributor

laeubi commented Apr 7, 2025

@srikanth-sankaran can you probably have a look? Looks like all constructor parameter of a record are not marked as "unused".

@ptziegler
Copy link
Copy Markdown
Contributor Author

The four new compiler warnings are about the parameters of the RequiredPackageVersionRange record, which is unrelated to this PR and from my perspective also wrong.

I get the same warning in the IDE, seems an issue of JDT, should we keep this PR as a reference for now?

That seems to be already fixed via eclipse-jdt/eclipse.jdt.core#3905. So I think it's save to merge the PR?

@iloveeclipse
Copy link
Copy Markdown
Member

That seems to be already fixed via eclipse-jdt/eclipse.jdt.core#3905. So I think it's save to merge the PR?

If there are no other pending actions, yes.

Copy link
Copy Markdown
Member

@HannesWell HannesWell 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. Thanks for the fix and I'm glad that the review lead to an even simpler solution. :)

@HannesWell HannesWell merged commit 1478eca into eclipse-pde:master Apr 8, 2025
19 checks passed
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.

BundleException on shutdown

4 participants