Skip to content

Commit 1344c9a

Browse files
akurtakovHannesWell
authored andcommitted
Restore supplier-disposal link in ClassRequestor without jakarta
The E4 Injector was decoupled from jakarta annotations by replacing the ClassRequestor pseudo-dependency descriptor with an empty array, in: - eclipse-platform#2649 That pseudo-link is what notifies an injected object when its supplier is disposed. With an empty descriptor the link is no longer established, so @PreDestroy of objects that only use constructor/@PostConstruct injection (no @Inject links) is no longer guaranteed to run before the supplying context is disposed. This broke disposal ordering and surfaced as a failure of PartRenderingEngineTests.testBut336225. Restore a non-empty, optional descriptor without re-introducing jakarta: use a private marker interface InjectionLink that is never available from any supplier together with e4's own @optional annotation. This keeps the injector free of specific jakarta annotation classes (the goal of the previous change) while re-establishing the supplier-disposal link. Fixes eclipse-platform#2700
1 parent b721651 commit 1344c9a

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/ClassRequestor.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
*******************************************************************************/
1414
package org.eclipse.e4.core.internal.di;
1515

16+
import java.lang.reflect.Field;
1617
import org.eclipse.e4.core.di.IInjector;
1718
import org.eclipse.e4.core.di.InjectionException;
19+
import org.eclipse.e4.core.di.annotations.Optional;
1820
import org.eclipse.e4.core.di.suppliers.IObjectDescriptor;
1921
import org.eclipse.e4.core.di.suppliers.PrimaryObjectSupplier;
2022

@@ -26,7 +28,23 @@
2628
*/
2729
public class ClassRequestor extends Requestor<Class<?>> {
2830

29-
private static IObjectDescriptor[] pseudoVariableDescriptor = {};
31+
private interface InjectionLink {
32+
// Marker type for the pseudo dependency. It is intentionally never available
33+
// from any supplier, so the (optional) dependency never resolves to a value.
34+
}
35+
36+
@Optional
37+
private static final InjectionLink PSEUDO_VARIABLE = null;
38+
static {
39+
try {
40+
Field field = ClassRequestor.class.getDeclaredField("PSEUDO_VARIABLE"); //$NON-NLS-1$
41+
pseudoVariableDescriptor = new IObjectDescriptor[] {
42+
new ObjectDescriptor(field.getGenericType(), field.getAnnotations()) };
43+
} catch (NoSuchFieldException e) {
44+
throw new IllegalStateException(e); // the field is declared right above, this cannot happen
45+
}
46+
}
47+
private static final IObjectDescriptor[] pseudoVariableDescriptor;
3048

3149
public ClassRequestor(Class<?> clazz, IInjector injector, PrimaryObjectSupplier primarySupplier, PrimaryObjectSupplier tempSupplier, Object requestingObject, boolean track) {
3250
super(clazz, injector, primarySupplier, tempSupplier, requestingObject, track);

0 commit comments

Comments
 (0)