2011-11-10 3 views
4

J'ai une application Java où j'utilise Akka Typed Actors. Le code n'a pas d'erreurs dans Eclipse, mais quand je commence ma demande, il se bloque et imprime cette erreur:Akka Actors échoue, VerifyError: cadres stackmap incompatibles à la cible de la branche

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) 

Je ne comprends pas ce qui peut se tromper. J'ai vérifié mon com.example.actors.DBActor.getItems() mais il n'y a pas d'erreur. Quel pourrait être le problème?


MISE À JOUR

Ci-dessous est par exemple le code où je reçois cette erreur. Je ces jar-fichiers sur le "chemin de génération" dans Eclipse:

  • derby.jar (de JDK7) (seulement une base de données en mémoire est utilisée dans cet exemple)
  • akka-actor-1.2.jar
  • akka-typed-actor-1.2.jar
  • aspectwerkz-2.2.3.jar
  • scala-library.jar

ici i s le 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(); 
    } 
} 
+0

Cela peut se produire lorsque le code octet code généré est construit incorrectement. Je voudrais essayer une version antérieure (ou une version ultérieure) –

+0

@Peter: J'avais une version antérieure avant, mais j'ai eu la même erreur mais sur une méthode différente. – Jonas

+0

TypedActors dans Akka <2.0 utilise AspektWerkz bytecode tissage, je n'ai aucune idée de ce qui pourrait causer votre problème, mais si vous pouvez réduire le problème et soumettre un ticket quelqu'un pourrait y jeter un coup d'oeil. –

Répondre

4

J'ai trouvé que ce bug est dans des endroits où j'utilise plusieurs ressources en un seul Java 7 instruction try-with-ressources.

E.g. ce code aura le bug:

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

    // do something 

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

et une solution ressemblerait à ceci:

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

     // do something 

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

Je n'ai jamais vu essayer avec des paramètres() – ZiglioUK

1

run java avec l'option -XX: -UseSplitVerifier

+0

"Avertissement OpenJDK 64-Bit Server VM: option ignorer UseSplitVerifier, le support a été supprimé dans 8.0" –

Questions connexes