Akka Actors fails, VerifyError: Inconsistent stackmap frames at branch target
Asked Answered
S

2

4

I have a Java application where I use Akka Typed Actors. The code has no errors in Eclipse, but when I start my application it crashes and prints this error:

Exception in thread "main" java.lang.VerifyError: Inconsistent stackmap frames at branch target 266 in method com.example.actors.DBActor.getItems(Lorg/joda/time/DateTime;Lorg/joda/time/DateTime;)I at offset 170
    at com.example.ui.Main$1.create(Main.java:31)
    at akka.actor.TypedActor$$anonfun$newInstance$3.apply(TypedActor.scala:677)
    at akka.actor.TypedActor$$anonfun$newInstance$3.apply(TypedActor.scala:677)
    at akka.actor.TypedActor$.newTypedActor(TypedActor.scala:847)
    at akka.actor.TypedActor$$anonfun$newInstance$1.apply(TypedActor.scala:601)
    at akka.actor.TypedActor$$anonfun$newInstance$1.apply(TypedActor.scala:601)
    at akka.actor.LocalActorRef.akka$actor$LocalActorRef$$newActor(ActorRef.scala:1084)
    at akka.actor.LocalActorRef$$anonfun$2.apply(ActorRef.scala:628)
    at akka.actor.LocalActorRef$$anonfun$2.apply(ActorRef.scala:628)
    at akka.util.ReentrantGuard.withGuard(LockUtil.scala:20)
    at akka.actor.LocalActorRef.<init>(ActorRef.scala:628)
    at akka.actor.Actor$.actorOf(Actor.scala:249)
    at akka.actor.TypedActor$.newInstance(TypedActor.scala:677)
    at akka.actor.TypedActor.newInstance(TypedActor.scala)
    at com.example.ui.Main.main(Main.java:29)

I don't understand what can be wrong. I have check my com.example.actors.DBActor.getItems() but there is no error in it. What could be wrong?


UPDATE

Below is example on code where I get this error. I have these jar-files on the "Build path" in Eclipse:

  • derby.jar (from JDK7) (only an in-memory database is used in this example)
  • akka-actor-1.2.jar
  • akka-typed-actor-1.2.jar
  • aspectwerkz-2.2.3.jar
  • scala-library.jar

Here is the code:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import akka.actor.TypedActor;
import akka.actor.TypedActorFactory;


public class App {

    public App() {
        TypedActor.newInstance(Backend.class, new TypedActorFactory() {
            public TypedActor create() {
                return new DataActor();
            }
        });
    }

    class DataActor extends TypedActor implements Backend {

        @Override
        public void insertData(String msg) {
            final String sqlSelect = "SELECT msg FROM SESSION.messages "+
                                     "WHERE to_user_id = ? AND from_user_id = ?";
            final String connectionURL = "jdbc:derby:memory:memdatabase;create=true";

            /* if this declaration is moved to where the string is used 
               in the conditional, the conditional can be used */
            String result;

            try(Connection conn = DriverManager.getConnection(connectionURL);) {

                try(PreparedStatement ps = conn.prepareStatement(sqlSelect);
                    ResultSet rs = new QueryHelper(ps)
                                    .integer(13).integer(26).executeQuery();) {

                    /* this doesn't work */

                    result = (rs.next()) ? rs.getString("text")
                                         : null;

                    /* but this work:

                     String result = (rs.next()) ? rs.getString("text")
                                                 : null;
                     */

                    /* this works fine 

                    while(rs.next()) {
                        result = rs.getString("msg");
                    }                                   */
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    class QueryHelper {
        private final PreparedStatement ps;
        private int index = 1;

        public QueryHelper(PreparedStatement ps) {
            this.ps = ps;
        }

        public QueryHelper integer(int param) throws SQLException {
            ps.setInt(index++, param);
            return this;
        }

        public ResultSet executeQuery() throws SQLException {
            return ps.executeQuery();
        }
    }

    public interface Backend {
        public void insertData(String text);
    }

    public static void main(String[] args) {
        new App();
    }
}
Slingshot answered 10/11, 2011 at 12:27 Comment(7)
This can occur when byte code generated code is built incorrectly. I would try an earlier release (or a later release)Unlearn
@Peter: I had an earlier release before, but I got the same error but on a different method.Slingshot
TypedActors in Akka < 2.0 uses AspektWerkz bytecode weaving, I have no idea on what could be causing your problem, but if you can minimize the problem and submit a ticket someone could have a look at it.Bevins
@ViktorKlang: May it be that I'm using Java 7? I will try to create a minimal program.Slingshot
I've seen the error with other byte-code enhancer / modifications when running on Java 7. The solution there was to explicitly compile the code for Java 6: -target 1.6 in javac.Pegmatite
@ViktorKlang: I have minimized the problem and posted the code now. I will look how I can submit a ticket now.Slingshot
try the jvm option "-XX:-UseSplitVerifier". i had the same error and it helped (with a completely different code piece though)Misconduct
S
4

I have found out that this bug is in places where I use multiple resources in a single Java 7 try-with-resources statement.

E.g. this code will have the bug:

try (Connection conn = DriverManager.getConnection(connURL);
     PreparedStatement ps = conn.prepareStatement(sql);) {

    // do something

} catch (SQLException e) {
    e.printStackTrace();
}

and a workaround would look like:

try (Connection conn = DriverManager.getConnection(connURL);) {
    try (PreparedStatement ps = conn.prepareStatement(sql);) {

        // do something

    }
} catch (SQLException e) {
    e.printStackTrace();
}
Slingshot answered 11/11, 2011 at 21:29 Comment(1)
I've never seen try with parameters ()Luxurious
H
1

run java with the option -XX:-UseSplitVerifier

Harmonium answered 21/9, 2014 at 14:31 Comment(1)
"OpenJDK 64-Bit Server VM warning: ignoring option UseSplitVerifier; support was removed in 8.0"Webbing

© 2022 - 2024 — McMap. All rights reserved.