Skip to content

Avoid final logger injection in EventSpyDispatcher#12145

Open
Will-thom wants to merge 1 commit into
apache:maven-3.10.xfrom
Will-thom:issue-12115-jdk26-final-field-warning-3.10
Open

Avoid final logger injection in EventSpyDispatcher#12145
Will-thom wants to merge 1 commit into
apache:maven-3.10.xfrom
Will-thom:issue-12115-jdk26-final-field-warning-3.10

Conversation

@Will-thom
Copy link
Copy Markdown

Fixes #12115.\n\nThis changes EventSpyDispatcher to use a static logger so Sisu does not mutate a final instance logger field reflectively on newer JDKs. It also adds a small regression test that guards against reintroducing a final instance Logger field.\n\nValidation:\n- mvn -B -pl maven-core -Dtest=EventSpyDispatcherTest test\n- mvn -B -pl maven-core test

Copy link
Copy Markdown
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

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

The fix itself is correct and follows the established convention in the codebase (private static final Logger LOGGER). This avoids Sisu mutating the final instance field on JDK 26+.

One thought on the test -- see inline comment.

Claude Code on behalf of Guillaume Nodet

.anyMatch(field -> !Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()));

assertFalse(hasFinalInstanceLogger);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test guards against reintroducing a final instance Logger field, but it would not catch someone reintroducing a non-final instance Logger field (which would still be subject to Sisu injection and equally problematic). A simpler and broader guard would be to assert that no instance Logger field exists at all:

Suggested change
}
boolean hasInstanceLogger = Arrays.stream(EventSpyDispatcher.class.getDeclaredFields())
.filter(field -> Logger.class.equals(field.getType()))
.anyMatch(field -> !Modifier.isStatic(field.getModifiers()));
assertFalse(hasInstanceLogger, "Logger field should be static to avoid Sisu reflective mutation");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMHO testing final presence is a little redundant ...

@slawekjaranowski
Copy link
Copy Markdown
Member

I'm not sure about we finally resolve a problem when Sisu mutating the final instance field ...

we have many other places in code with final without static.

@slawekjaranowski
Copy link
Copy Markdown
Member

@Will-thom please always preserve last paragraph from PR template

To make clear that you license your contribution under the Apache License Version 2.0, January 2004 you have to acknowledge this by using the following check-box.
...

Please also consider to sign - https://www.apache.org/licenses/icla.pdf

@cstamas
Copy link
Copy Markdown
Member

cstamas commented May 24, 2026

I would rather stop sisu/plexus (and i think this is rather plexus) doing this, AFAIR there was plan to inject Logger instances that was never finalized as Plexus Loggers are still in play (goal was to fully switch to slf4j)

@slawekjaranowski
Copy link
Copy Markdown
Member

In this case logger is slf4j ... but in some case sisu try to update such filed

@cstamas
Copy link
Copy Markdown
Member

cstamas commented May 24, 2026

See
https://github.com/eclipse-sisu/sisu-project/blob/a2d1d99282f37d366e7fe417c8c0fea4897c5704/org.eclipse.sisu.plexus/src/main/java/org/eclipse/sisu/plexus/PlexusLifecycleManager.java#L105

But something is off then, as in Maven Core of 3.10.x we should not have Plexus Components anymore, need to look more...

@cstamas
Copy link
Copy Markdown
Member

cstamas commented May 24, 2026

@Will-thom can you provide a reproducer for refd issue?

@cstamas
Copy link
Copy Markdown
Member

cstamas commented May 24, 2026

Also, this issue reminds me of dea5f14

There, we thought we migrated the component to Sisu (from Plexus) but in fact, we did not. So, if something still defines EventSpyDispatcher as Plexus component (instead of Sisu JSR330 component), then yes, this could happen. Otherwise, I don't know what exactly happens here...

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.

4 participants