Aladdin - Scala Bugtracking
[#1020] project: compiler priority: low category: bug
submitter assigned to status date submitted
Burak Iulian fixed 2007-03-24 23:16:03.0
subject exception woes
code
import java.sql.{Connection, SQLException}

trait ConnectionsBug {

  import javax.sql.DataSource

  def withConn(f:Connection => Unit, conn1:Connection) = {
    var conn  = conn1
    try {
      f(conn)
    } catch {
      case e:SQLException =>
        throw e
    } finally {
      // Always make sure result sets and statements are closed,
      // and the connection is returned to the pool
      if (conn != null) {
        try { conn.close(); } catch { case e:SQLException => ;  }
        conn = null;
      }
    }
  }

}
what happened
Burak-Emirs-MacBook-Pro:~/Documents/my_sources/kelimaat/kelimaat buraq$ ~/Documents/svn/scala/build/quick/bin/sc\
alac -d /tmp /tmp/bg.scala 
def withConn(conn1: java.sql.Connection (REFERENCE(java.sql.Connection)), f: scala.Function1 (REFERENCE(scala.Fu\
nction1)), $this: ConnectionsBug (REFERENCE(ConnectionsBug))): scala.Unit {
locals: value $this, value f, value conn1, variable conn, value e, variable exc0, variable eqEqTemp$, value e
startBlock: 1
blocks: [1,2,3,6,7,8,9,10,11,15,16,17,18,19,23,24,25,26]

1: 
  SCOPE_ENTER variable conn
  LOAD_LOCAL value conn1
  STORE_LOCAL variable conn
  JUMP 19
  
2: 
  RETURN (UNIT)
  
3: 
  STORE_LOCAL variable exc0
  LOAD_LOCAL variable conn
  DUP
  STORE_LOCAL variable eqEqTemp$
  CZJUMP (REFERENCE(java.lang.Object))EQ ? 6 : 7
  
6: 
  LOAD_LOCAL variable exc0
  THROW
  
7: 
  LOAD_LOCAL variable eqEqTemp$
  CONSTANT (Constant(null))
  CALL_METHOD java.lang.Objectjava.lang.Object.equals (dynamic)
  CZJUMP (BOOL)NE ? 6 : 10
  
8: 
  CONSTANT (Constant(null))
  DROP REFERENCE(scala.Null)
  CONSTANT (Constant(null))
  STORE_LOCAL variable conn
  JUMP 6
  
9: 
  STORE_LOCAL value e
  JUMP 8
  
10: 
  LOAD_LOCAL variable conn
  CALL_METHOD java.sql.Connectionjava.sql.Connection.close (dynamic)
  JUMP 8
  
11: 
  STORE_LOCAL value e
  LOAD_LOCAL value e
  THROW
  
15: 
  LOAD_LOCAL variable eqEqTemp$
  CONSTANT (Constant(null))
  CALL_METHOD java.lang.Objectjava.lang.Object.equals (dynamic)
  CZJUMP (BOOL)NE ? 2 : 18
  
16: 
  CONSTANT (Constant(null))
  DROP REFERENCE(scala.Null)
  CONSTANT (Constant(null))
  STORE_LOCAL variable conn
  JUMP 2
  
17: 
  STORE_LOCAL value e
  JUMP 16
  
18: 
  LOAD_LOCAL variable conn
  CALL_METHOD java.sql.Connectionjava.sql.Connection.close (dynamic)
  JUMP 16
  
19: 
  LOAD_LOCAL value f
  LOAD_LOCAL variable conn
  CALL_METHOD scala.Function1scala.Function1.apply (dynamic)
  DROP REFERENCE(java.lang.Object)
  LOAD_LOCAL variable conn
  DUP
  STORE_LOCAL variable eqEqTemp$
  CZJUMP (REFERENCE(java.lang.Object))EQ ? 2 : 23
  
23: 
  LOAD_LOCAL variable eqEqTemp$
  CONSTANT (Constant(null))
  CALL_METHOD java.lang.Objectjava.lang.Object.equals (dynamic)
  CZJUMP (BOOL)NE ? 2 : 26
  
24: 
  CONSTANT (Constant(null))
  DROP REFERENCE(scala.Null)
  CONSTANT (Constant(null))
  STORE_LOCAL variable conn
  JUMP 2
  
25: 
  STORE_LOCAL value e
  JUMP 24
  
26: 
  LOAD_LOCAL variable conn
  CALL_METHOD java.sql.Connectionjava.sql.Connection.close (dynamic)
  JUMP 24
  
}
Exception handlers: 
  catch (SQLException) in List(26) starting at: 25
    consisting of blocks: List(25)
    with finalizer: null
  catch (SQLException) in List(18) starting at: 17
    consisting of blocks: List(17)
    with finalizer: null
  catch (SQLException) in List(26,25,24,23,19) starting at: 11
    consisting of blocks: List(18,16,15,11)
    with finalizer: null
  catch (SQLException) in List(10) starting at: 9
    consisting of blocks: List(9)
    with finalizer: null
  catch () in List(26,25,24,23,19) starting at: 3
    consisting of blocks: List(10,8,7,6,3)
    with finalizer: null
  
Exception in thread "main" java.lang.Error: Invalid index for: value e{8918836}
Method: ConnectionsBug$class.withConn
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.assert(GenJVM.scala:1475)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.indexOf(GenJVM.scala:1266)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$41.apply(GenJVM.scala:728)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$41.apply(GenJVM.scala:650)
        at scala.Iterator$class.foreach(Iterator.scala:380)
        at scala.runtime.BoxedArray$$anon$0.foreach(BoxedArray.scala:46)
        at scala.Iterable$class.foreach(Iterable.scala:197)
        at scala.runtime.BoxedArray.foreach(BoxedArray.scala:25)
        at scala.tools.nsc.backend.icode.BasicBlocks$BasicBlock.traverse(BasicBlocks.scala:102)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genBlock(GenJVM.scala:650)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genBlocks(GenJVM.scala:571)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genBlocks(GenJVM.scala:571)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genBlocks(GenJVM.scala:571)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genBlocks(GenJVM.scala:571)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genBlocks(GenJVM.scala:571)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genCode(GenJVM.scala:560)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genMethod(GenJVM.scala:445)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$6.apply(GenJVM.scala:195)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$6.apply(GenJVM.scala:195)
        at scala.List.foreach(List.scala:702)
        at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genClass(GenJVM.scala:195)
        at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$0.apply(GenJVM.scala:44)
        at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$0.apply(GenJVM.scala:44)
        at scala.Iterator$class.foreach(Iterator.scala:380)
        at scala.collection.Map$$anon$2.foreach(Map.scala:119)
        at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase.run(GenJVM.scala:44)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:488)
        at scala.tools.nsc.Global$Run.compile(Global.scala:562)
        at scala.tools.nsc.Main$.process(Main.scala:57)
        at scala.tools.nsc.Main$.main(Main.scala:79)
        at scala.tools.nsc.Main.main(Main.scala)
what expected no error? I agree that "throw e" is maybe not very elegant, but should not crash the compiler in any case.
[back to overview]
Changes of this bug report
Burak  edited on  2007-03-24 23:19:47.0
ah, the bug seems to be related to the fact that the finally block contains another exception handling block, uncommenting it makes the crash go away.
Iulian  edited on  2007-03-26 14:57:05.0