1

I'm very new to Scala, so please excuse my basic question.

I'm trying to get Scala-Arm to manage the release of a class member, but having trouble with scoping.

Although the following code compiles, it fails with

java.lang.NoSuchMethodError: resource.ManagedResource.reflect()Ljava/lang/Object; 

on the reflect call. So it seems the the managed_file is being released immediately.

For local variables I have used the for (managed_file <- managed(...)) syntax but I can't see what to do here.

Suggestions anyone?

class Writer(outputPath: String){

  val managed_file = managed(new FileOutputStream(new File(outputPath)))

  def write(something : SomeClass) {
    var bos = new ByteArrayOutputStream
    var dos = new DataOutputStream(bos)

    try {
      dos.write(Marshal.dump(something))
      bos.writeTo(managed_file.reflect)
    } 
    finally {
      dos.close
      bos.close
    }
  }
}
om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
puppet
  • 660
  • 1
  • 5
  • 8

1 Answers1

0

NoSuchMethodError is a compilation/runtime difference error. You compile succesfully against Scal ARM, but this one is not found (or at least not found in same version) during runtime.

cchantep
  • 9,118
  • 3
  • 30
  • 41
  • Thanks for your help. I've searched my system and I have only a single Scala ARM JAR. I've updated my classpath to explicitly reference it but I get still the same behavior. Wouldn't a run-time resolution problem mean I should get the same error using the local variable `for(managedFile <- managed(...))` syntax? – puppet Aug 04 '14 at 12:50
  • NoSuchMethodError can't be a syntax, which would be detected by compiler. Have you tried your code in REPL (launching console from SBT CLI)? – cchantep Aug 04 '14 at 14:13
  • Thanks again. I just tried running it from REPL and got the same result. This wasn't via SBT though, I'm not sure how to do that, I'll look into it tomorrow. – puppet Aug 05 '14 at 18:40
  • In SBT REPL, try `classOf[resource.ManagedResource].getMethod("reflect", Array[Class]())` – cchantep Aug 05 '14 at 19:23
  • And in SBT try `show dependencyClasspath` to check from which JAR Scala-ARM is loaded. – cchantep Aug 05 '14 at 21:37
  • Hi again, I can see from `show dependencyClasspath` there's something funny going on with the resolution of Scala-ARM. I'll be able to resolve it from here with that info, so I'm going to mark this as resolved. Thanks. – puppet Aug 07 '14 at 19:22