Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9197701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:07:56+00:00 2026-06-17T22:07:56+00:00

Running the code below results in the error message Bad type on operand stack

  • 0

Running the code below results in the error message Bad type on operand stack.

public static void main(String args[]) {
        TransformService transformService = (inputs) -> {
            return new ArrayList<String>(3) {{
                add("one");
                add("two");
                add("three");
            }};
        };

        Collection<Integer> inputs = new HashSet<Integer>(2) {{
            add(5);
            add(7);
        }};
        Collection<String> results = transformService.transform(inputs);
        System.out.println(results.size());
    }

    public interface TransformService {
        Collection<String> transform(Collection<Integer> inputs);
    }

However removing the double brace initialization (anonymous inner classes) within the lamda allows the code to run as expected, why ? The below works :

public class SecondLambda {
    public static void main(String args[]) {
        TransformService transformService = (inputs) -> {
            Collection<String> results = new ArrayList<String>(3);
            results.add("one");
            results.add("two");
            results.add("three");

            return results;
        };

        Collection<Integer> inputs = new HashSet<Integer>(2) {{
            add(5);
            add(7);
        }};
        Collection<String> results = transformService.transform(inputs);
        System.out.println(results.size());
    }

    public interface TransformService {
        Collection<String> transform(Collection<Integer> inputs);
    }
}

Compiler bug ? It is the early access version after all …

(This won’t compile unless you have the latest jdk 8 lambda download.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:07:57+00:00Added an answer on June 17, 2026 at 10:07 pm

    It seems, that problem occurs not only in case when lambda returns anonymous type, but even if any anonymous class is constructed inside lambda. I.e.:

    public class TestLambda {
        public static void main(String[] args) {
            xxx();
        }
        static void xxx() {
            Functional1 f  = () -> {
                Object o = new Object() { };
                return new A();
            };
        }
        static class A { }
        static interface Functional1 { A func(); }
    }
    

    This actually leads to Exception in thread "main" java.lang.VerifyError: Bad local variable type (…) Reason: Type top (current frame, locals[0]) is not assignable to reference type.

    Further investigation shows, that if we will introduce parameter into method xxx, the reason for an exception will contains its type. E.g.:

    Type 'java/lang/Integer' (current frame, stack[0]) is not assignable to 'lambda/TestLambda'

    And this is already very interesting. Let’s change type of xxx parameter (which is not actually used) to type of top class, i.e. TestLambda:

    ...
        xxx(new TestLambda());
    }
    private static void xxx(TestLambda x) {
    ...
    

    And what do you think? This fixes the problem! Everything begin work well. Even, if we will change return A(); to return new A() {};. Check this!


    My conclusion is that this is real JVM bug. It seems, that the problem is with stack of loaded classes. It occurs in combine with method, which Java uses for translating lambda expressions (http://cr.openjdk.java.net/~briangoetz/lambda/lambda-translation.html) – it produces synthetic methods inside top class. It seems, that when anonymous classes are introduced in lambda stack becomes broken. It could be fixed using mentioned workaround.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the following error when running the code below: invalid byte sequence in
While running the code I've included below I receive the error EntityCommandExecutionException was unhandled
I get the below error when running the below code on a controller. Please
Hello friends i am running code given below which contains the setLogTimeEntery function and
I am getting an argument of length zero after running the code below. I
I am running below code as root and using python2.6.1, platform is linux >>>
I have a number of nodejs applications running on Express using the code below.
My code is below: I am seeing that on running the app the loadWidget
I am using the below code to find the base address of a running
I wanted to generate a list view using below code. But after running this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.