Skip to content

Bug: SnapStart class priming loads 0 classes when classesloaded.txt has leading whitespace #2559

Description

@phipag

Expected Behaviour

ClassPreLoader.preloadClasses() loads every class listed in a module's classesloaded.txt during the SnapStart beforeCheckpoint phase, so those classes are baked into the snapshot and restore time drops.

Current Behaviour

ClassPreLoader loads 0 classes from powertools-tracing, because every line in its classesloaded.txt starts with a leading space. The parser calls line.stripTrailing(), which removes trailing whitespace but keeps the leading space. Class.forName(" java.lang.Object", ...) then throws ClassNotFoundException, and the loader silently swallows it for all 5996 entries. The priming hook runs but primes nothing.

powertools-tracing ships this format today, so its automatic priming is a no-op in released versions. powertools-large-messages (PR #2533) uses the same format. The other modules (kafka, lambda-metadata, metrics, validation) have no leading space and are unaffected.

Code snippet

// ClassPreLoader.preloadClassesFromStream
final String className = line.stripTrailing(); // keeps the leading space
if (!className.isBlank()) {
    loadClassIfFound(className); // Class.forName(" java.lang.Object") -> ClassNotFoundException
}

Possible Solution

Replace line.stripTrailing() with line.strip() so leading whitespace is removed as well. strip() tolerates both file formats, so no resource files need to change. I verified the fix on a deployed function: loaded classes went from 0 to 4062.

Steps to Reproduce

  1. Deploy a Lambda that uses powertools-tracing with SnapStart enabled (ApplyOn: PublishedVersions), and reference TracingUtils during INIT so the priming hook runs.
  2. Add a temporary debug log in ClassPreLoader reporting how many classes loaded.
  3. Observe that 0 classes load, because every classesloaded.txt entry carries a leading space.

Powertools for AWS Lambda (Java) version

latest

AWS Lambda function runtime

Java 11

Debugging logs

SnapStart priming: starting class preloading from 'classesloaded.txt'
SnapStart priming: successfully loaded 0 class(es) from resource

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Working on it

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions