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

Provide guidelines in AspectJ documentation to avoid dumps #27650

Closed
kriegaex opened this issue Nov 7, 2021 · 2 comments
Closed

Provide guidelines in AspectJ documentation to avoid dumps #27650

kriegaex opened this issue Nov 7, 2021 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: documentation A documentation task
Milestone

Comments

@kriegaex
Copy link
Contributor

kriegaex commented Nov 7, 2021

Preface

When using spring-aspects with native AspectJ LTW, the AspectJ weaving agent core-dumps, at least in some Spring Boot playground projects I am using in order to answer AOP-related StackOverflow questions. I am not sure if this is is specific to Spring Boot (did not try without it) and ought to be fixed there, or if it is a Spring Core (spring-aspects) problem. Maybe, it even needs some work in AspectJ. Probably the best person to answer that is @aclement, who I had a private conversation with about this issue already.

Either way, it is an issue that needs to be tracked here, because it affects Spring users.

Issue description

As discussed in StackOverflow question #69800420, running a minimal Spring Boot application with JVM parameters (parameter in a single line, of course, and the first one only necessary for JDK 16+)

--add-opens java.base/java.lang=ALL-UNNAMED
-javaagent:.../aspectjweaver-1.9.7.jar
-javaagent:.../spring-instrument-5.3.12.jar

yields ajcore.*.txt core dump files created by AspectJ. Corresponding stack traces featuring MissingResolvedTypeWithKnownSignature are logged to the console. The missing resolved type varies between Spring Boot versions and is e.g. org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer for Boot 2.3.3 and org.springframework.boot.jdbc.DataSourceBuilder.OraclePoolDataSourceProperties for Boot 2.5.6.

How to reproduce

  • Clone the repository found at https://github.com/kriegaex/SO_AJ_SpringTransactionalNotApplied_69789179
  • Check out branch aspectj if you prefer Gradle and branch aspectj-with-maven for Maven. The code in both branches is equivalent, only the build tool differs.
  • Build and run the sample application, currently based on Spring Boot 2.5.6, adding the JVM parameters mentioned above to the command line. Because the Git repository already contains a workaround configration in a custom aop.xml file, you are not going to see any problems.
  • In order to reproduce the problem, simply either delete the aop.xml file or comment out the <exclude within="..."/> tags.

Workaround

The default aop.xml for spring-aspects simply declares aspects and no further weaving options.

A simple way to avoid the core dumps is to exclude problematic target classes from weaving. Even if a future AspectJ release would contain a fix avoiding the core dumps, until then Spring Core could avoid weaving unwanted classes and/or packages by excluding them like I have shown in my custom aop.xml file:

<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>

  <!-- Be verbose about registered aspects, woven joinpoints and Xlint warnings -->
  <!--<weaver options="-verbose -showWeaveInfo">-->
  <!-- Be less noisy, suppressing Xlint warnings and info about registered aspects -->
  <weaver options="-showWeaveInfo -Xlint:ignore">

    <!-- Avoiding AspectJ core dump files 'ajcore.*.txt' by only weaving classes in application-specific packages -->
    <!--<include within="com.example.aspectj..*"/>-->

    <!-- Avoid AspectJ core dump files 'ajcore.*.txt' for Spring Boot 2.5.6-->
    <exclude within="org.springframework.boot.jdbc.DataSourceBuilder.OraclePoolDataSourceProperties"/>

    <!-- Avoid AspectJ core dump files 'ajcore.*.txt' for Spring Boot 2.3.3-->
    <exclude within="org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer"/>

  </weaver>

</aspectj>

These weaver options could be merged into the upstream aop.xml for spring-instruments. Otherwise, all users would have to create a custom aop.xml by themselves like I did, just so as to avoid an upstream problem.

BTW, the weaver by default prints lots of [Xlint:cantFindType] warnings, which do no harm but clutter the console log. You might also want to consider adding the -Xlint:ignore weaver option. Another helpful default option is -showWeaveInfo, because it would show to the user by default all woven joinpoints. I think the latter is more desireable than the Xlint messages. But both options are unrelated to the workaround for this issue, I am just mentioning them as ideas for improvement.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 7, 2021
@rstoyanchev rstoyanchev added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 10, 2021
@sdeleuze sdeleuze self-assigned this Jan 5, 2024
@sdeleuze sdeleuze added type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 10, 2024
@sdeleuze sdeleuze added this to the 6.1.3 milestone Jan 10, 2024
@sdeleuze sdeleuze changed the title AspectJ core dumps (ajcore.*.txt) for spring-aspects Provide guidelines in AspectJ documentation to avoid core dumps Jan 10, 2024
@sdeleuze
Copy link
Contributor

After a related team discussion, I am turning this issue into a documentation one.

@sdeleuze sdeleuze changed the title Provide guidelines in AspectJ documentation to avoid core dumps Provide guidelines in AspectJ documentation to avoid dumps Jan 10, 2024
@kriegaex
Copy link
Contributor Author

kriegaex commented Jan 11, 2024

@sdeleuze, I do not think that this is sufficient and only a docs issue, because like I said, spring-aspects has its own aop.xml file in its belly, and it produces those AspectJ core dumps out of the box with Spring Boot. I do not think, it is the user's responsibility to always override the settings from there. She might not even be aware of the fact that there is such a thing as aop.xml, but simply turn on LTW mode for transactions or for injecting Spring beans into non-Spring classes. By first ignoring this issue for 2 years and then just documenting something, it does not go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

4 participants