Skip to content

Spring boot 2.8.x fat jars compiled under Java 8 and run in Java 8 runtime crash #2976

Description

@jtduffy

Description

This is from a #java-agent issue.

When running a spring boot application compiled under Java 8 and running under a Java 8 run time, the app fails to start. This happens regardless if the app is run as a fat jar or an exploded jar.

When launching a spring boot app, the JarLauncher configures the classpath for Spring's PathMatchingResourcePatternResolver class, and adds the agent jar as a candidate for component scanning. The agent shadows both version 2 and 3 of the Caffeine cache framework. Version 3 only supports Java 11 and up, so when Spring scans the agent jar when running under Java 8, it encounters annotations values a class that don't exist in Java 8, which causes the crash. So something in the customer's app is declaring a some sort of "catch-all" component scan pattern that is picking up "com.newrelic" namespaced classes.

The problem class is the NullMarked class from jspecify, which is a Caffeine dependency. In the version of jspecify that Caffeine 3 uses, the MODULE value was added to the @Target annotation of that class. MODULE doesn't exist in Java 8, which cause the crash when Spring scans the class metadata.

The possible workarounds are:

  • Drop to version 9.1.0 of the agent (no caffeine 3)
  • Correct the ComponentScan pattern. It's technically an error that a runtime agent is being component scanned by Spring
  • Run the app under Java 9+ (Java 11 would be recommended since it's an LTS release)

Simple boot 2.7.18 repro.

Possible agent solution:
During the shadow process, do a bytecode rewrite of the jspecify NullMarked class to remove the ``MODULEvalue from the@Target` annotation. Probably also check for/remove `RECORD_COMPONENT` to future proof since it was added in J 16.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Needs Review

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions