Interpret the Java stack trace with lambdas, for example, ".lambda $ null $ 2" & and "$$ Lambda $"

I am looking for a definition of the parts that occur around lambda in a 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 throws this exception.

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

What are the different parts describing the exception? What does "zero", "2", "64", "730559617" and "Unknown source" tell me?

A more detailed example can be found here (but there is no β€œnull” in my exception above). http://blog.takipi.com/the-dark-side-of-lambda-expressions-in-java-8/

+6
source share
1 answer

There is no standard definition for this generated class name. This is intentional so that you do not write code that depends on it, which complicates the work of designers later.

Having said that you can read,

  • The first part of the class name is the call site class.
  • the number before the last $ is the global counter for lambda. It depends on the order in which the code for lambdas is generated.
  • a large number is the generated identifier. It is different for the same lambda every time you run, but does not change after you start.

An "unknown source" tells you that this generated code does not have debugging information associated with it.

We are looking at a library for modifying toString for lambda to give you an idea of ​​the code associated with it. that is, it will look like a lambda code, at least for trivial cases.

+3
source

All Articles