Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the java.lang.invoke.LambdaForm$Hidden annotation is runtime annotation?

I've discovered what exactly annotations have classes in the final app. I need it because these annotations are using by some jar transformations in building process, but it is another story.

So my question is why the java.lang.invoke.LambdaForm$Hidden annotation is runtime annotation? What component uses it? Why?

like image 547
tse Avatar asked May 16 '26 18:05

tse


1 Answers

It is used by the JVM runtime to hide lambda related frames in the stacktrace. Take this example:

public class LambdaStackTrace 
{
    public static void main(String[] args) throws Exception 
    {
        "a".chars().forEach(c -> {
            new Error().printStackTrace();
        });
    }
}

It will produce this stacktrace:

java.lang.Error
    at LambdaStackTrace.lambda$0(LambdaStackTrace.java:6)
    at java.lang.CharSequence$1CharIterator.forEachRemaining(CharSequence.java:149)
    at java.util.Spliterators$IntIteratorSpliterator.forEachRemaining(Spliterators.java:1908)
    at java.util.stream.IntPipeline$Head.forEach(IntPipeline.java:557)
    at LambdaStackTrace.main(LambdaStackTrace.java:5)

But if look at the frame stack in a debugger it will show you an additional frame which has a @Hidden annotation:

enter image description here

like image 184
wero Avatar answered May 19 '26 07:05

wero