11

I'm looking for a definition of the parts that occurs around a lambda in the Java 8 stack trace

For example this code

Object inputData = someData();

myList.stream().forEach(listItem -> {

    Query query = (Query) listItem.getSingle().apply(this.getId());

    Object data = diffUtils.applyProjection(query, inputData);

    myStringCollection.stream()
       .filter(destination -> myPredicateMethod(listItem, destination))
       .forEach(destination -> myProcessMethod(destination, data));
}

sometimes produces this exception.

at [CLASS].lambda$null$2([CLASS].java:85)
at [CLASS]$$Lambda$64/730559617.accept(Unknown Source)

What is the different parts describing in the exception? What is the "null", "2", "64", "730559617" and "Unknown Source" telling me?

A more elaborated example can be found here (but here the "null" in my exception above is not present). http://blog.takipi.com/the-dark-side-of-lambda-expressions-in-java-8/

Andreas Lundgren
  • 12,043
  • 3
  • 22
  • 44
  • Possible duplicate of [Identifying lambdas in stacktrace in Java 8](http://stackoverflow.com/questions/29435888/identifying-lambdas-in-stacktrace-in-java-8) – Alex Shesterov May 20 '17 at 22:17

1 Answers1

7

There is no standard definition for that this generated class name is. This is deliberate to avoid you writing code which depends on it making it harder for the designers to change it later.

That being said, what little you can read is;

  • the first part of the class name is the class of the call site.
  • the number before the last $ is global counter for lambda. This depends on the order in which code for lambdas is generated.
  • the big number is a generated id. It is different for the same lambda each time you run but doesn't change once you have started.

The "Unknown Source" is telling you this generated code has no debug information associated with it.

We are looking at a library for changing the toString for a lambda to give you an idea of code associated with it. i.e. it will look like the code of the lambda at least for trivial cases.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130