Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda expression throws exception

I just started a new vaadin project with maven (com.vaadin:[email protected]).

In the default MyVaadinUI.java i have replaced the Butten.ClickListener() with a lambda expression, after that i get a exception while running package jetty:run

Before:

Button button = new Button("Click Me");
  button.addClickListener(new Button.ClickListener() {
    public void buttonClick(ClickEvent event) {
      layout.addComponent(new Label("Thank you for clicking"));
    }
});
layout.addComponent(button);

After:

Button button = new Button("Click Me");
button.addClickListener(event -> layout.addComponent(new Label("Thank you for clicking")));
layout.addComponent(button);

Exception:

2014-08-26 13:23:30.069:WARN:oeja.AnnotationParser:EXCEPTION 
java.lang.ArrayIndexOutOfBoundsException: 1612
    at org.objectweb.asm.ClassReader.readClass(Unknown Source)
    at org.objectweb.asm.ClassReader.accept(Unknown Source)
    at org.objectweb.asm.ClassReader.accept(Unknown Source)
    at org.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:899)
    at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:755)
    at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:744)
    at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:744)
    at org.mortbay.jetty.plugin.MavenAnnotationConfiguration.doParse(MavenAnnotationConfiguration.java:73)
    at org.mortbay.jetty.plugin.MavenAnnotationConfiguration.parseWebInfClasses(MavenAnnotationConfiguration.java:52)
    at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:119)
    at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:468)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1237)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
    at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:298)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
    at org.eclipse.jetty.server.Server.doStart(Server.java:282)
    at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:520)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:365)
    at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:523)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

I`m using IntelliJ13.1 with JDK8 on OSX

like image 368
cebor Avatar asked Aug 26 '14 11:08

cebor


People also ask

How do you handle exception thrown by lambda expression?

Because IOException is a checked exception, we must handle it explicitly. We have two options. First, we may simply throw the exception outside of our method and take care of it somewhere else. Alternatively, we can handle it inside the method that uses a lambda expression.

Can Lambda throw exception Java?

As with a method, you can throw two kinds of exceptions in a lambda expression: predefined Java types (ArithmeticException, ArrayIndexOutOfBoundsException, etc.);

Can Lambda throw exception C++?

Throwing an exception from a lambda function is equivalent like throwing an exception from any other function.


1 Answers

I faced this issue when I deployed the app in jetty 8.12.x. I resolved the issue by upgrading to jetty 9.2.x. (Yes, lambdas are used in app)

like image 117
Thamme Gowda Avatar answered Oct 26 '22 23:10

Thamme Gowda