Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load.exec in predef.scala causes NPE in 0.5.9 or 0.6.0? #400

Closed
ches opened this issue Jun 10, 2016 · 4 comments
Closed

load.exec in predef.scala causes NPE in 0.5.9 or 0.6.0? #400

ches opened this issue Jun 10, 2016 · 4 comments
Labels

Comments

@ches
Copy link

ches commented Jun 10, 2016

I have the following ~/.ammonite/predef.scala:

// See http://www.lihaoyi.com/Ammonite/#Configuration

// Not really digging the @ sign prompt.
repl.prompt() = "\n> "

// Love the double negative... enable compiler warnings
compiler.settings.nowarnings.value = false

// Load utility definitions shared with default scala REPL
try load.exec(ammonite.ops.home/".config"/'scala/"replinit.scala")
catch { case _: Exception => println("=== replrc not loaded! ===") }

This was working fine in 0.5.8, but in 0.6.0 there's an exception. The real contents of my ~/.config/scala/replinit.scala seem to be irrelevant, I can reduce it to this and it still blows up:

val foo = 1 + 1

If I remove the try, here's the stack trace I get from amm failing to launch:

$ amm
Loading...
Exception in thread "main" java.lang.RuntimeException: Error during Predef:
        at ammonite.repl.interp.Interpreter$$anonfun$17.apply(Interpreter.scala:522)
        at ammonite.repl.interp.Interpreter$$anonfun$17.apply(Interpreter.scala:511)
        at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:124)
        at scala.collection.immutable.List.foldLeft(List.scala:84)
        at ammonite.repl.interp.Interpreter.<init>(Interpreter.scala:511)
        at ammonite.repl.Repl.<init>(Repl.scala:41)
        at ammonite.repl.Main.instantiateRepl(Main.scala:57)
        at ammonite.repl.Main.run(Main.scala:68)
        at ammonite.repl.Main$$anonfun$main$2.apply(Main.scala:258)
        at ammonite.repl.Main$$anonfun$main$2.apply(Main.scala:244)
        at scala.Option.foreach(Option.scala:257)
        at ammonite.repl.Main$.main(Main.scala:244)
        at ammonite.repl.Main.main(Main.scala)
Caused by: java.lang.NullPointerException
        at scala.collection.generic.GenericTraversableTemplate$$anonfun$flatten$1.apply(GenericTraversableTemplate.scala:172)
        at scala.collection.generic.GenericTraversableTemplate$$anonfun$flatten$1.apply(GenericTraversableTemplate.scala:171)
        at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
        at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:35)
        at scala.collection.generic.GenericTraversableTemplate$class.flatten(GenericTraversableTemplate.scala:171)
        at scala.collection.AbstractTraversable.flatten(Traversable.scala:104)
        at ammonite.repl.interp.Frame$.mergeImports(ClassLoaders.scala:22)
        at ammonite.repl.interp.Interpreter.loop$1(Interpreter.scala:204)
        at ammonite.repl.interp.Interpreter.processCorrectScript(Interpreter.scala:220)
        at ammonite.repl.interp.Interpreter.processScript(Interpreter.scala:249)
        at ammonite.repl.interp.Interpreter.processExec(Interpreter.scala:112)
        at ammonite.repl.interp.Interpreter$$anon$1$load$.apply(Interpreter.scala:331)
        at ammonite.repl.interp.Interpreter$$anon$1$load$.exec(Interpreter.scala:337)
        at ammonite.predef.LoadedPredef$.<init>(LoadedPredef.scala:10)
        at ammonite.predef.LoadedPredef$.<clinit>(LoadedPredef.scala:10)
        at ammonite.predef.LoadedPredef.$main(LoadedPredef.scala)
        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:498)
        at ammonite.repl.interp.Evaluator$$anon$1.ammonite$repl$interp$Evaluator$$anon$$evalMain(Evaluator.scala:173)
        at ammonite.repl.interp.Evaluator$$anon$1$$anonfun$processScriptBlock$2$$anonfun$apply$16.apply(Evaluator.scala:341)
        at ammonite.repl.interp.Evaluator$$anon$1$$anonfun$processScriptBlock$2$$anonfun$apply$16.apply(Evaluator.scala:338)
        at ammonite.repl.Catching.map(Util.scala:36)
        at ammonite.repl.interp.Evaluator$$anon$1$$anonfun$processScriptBlock$2.apply(Evaluator.scala:338)
        at ammonite.repl.interp.Evaluator$$anon$1$$anonfun$processScriptBlock$2.apply(Evaluator.scala:335)
        at ammonite.repl.Res$Success.flatMap(Util.scala:54)
        at ammonite.repl.interp.Evaluator$$anon$1.processScriptBlock(Evaluator.scala:335)
        at ammonite.repl.interp.Interpreter$$anonfun$processModule0$1$$anonfun$apply$4.apply(Interpreter.scala:101)
        at ammonite.repl.interp.Interpreter$$anonfun$processModule0$1$$anonfun$apply$4.apply(Interpreter.scala:101)
        at ammonite.repl.interp.Interpreter.withContextClassloader(Interpreter.scala:61)
        at ammonite.repl.interp.Interpreter$$anonfun$processModule0$1.apply(Interpreter.scala:100)
        at ammonite.repl.interp.Interpreter$$anonfun$processModule0$1.apply(Interpreter.scala:99)
        at ammonite.repl.interp.Interpreter.loop$1(Interpreter.scala:202)
        at ammonite.repl.interp.Interpreter.processCorrectScript(Interpreter.scala:220)
        at ammonite.repl.interp.Interpreter.processScript(Interpreter.scala:249)
        at ammonite.repl.interp.Interpreter.processModule0(Interpreter.scala:96)
        at ammonite.repl.interp.Interpreter$$anonfun$17.apply(Interpreter.scala:513)
        ... 12 more
@ches
Copy link
Author

ches commented Jun 10, 2016

Probably obvious, but I can remove the predef.scala or comment out the load.exec and the REPL launches without problem. Running the load.exec in the REPL after it's launched works fine.

@lihaoyi lihaoyi added the bug label Jun 11, 2016
@lihaoyi
Copy link
Member

lihaoyi commented Jun 14, 2016

Thanks for the report! I appears I fixed the load.exec by accident in b76c607#diff-bcdb6a0282e047eba770bc309743e114R310, but load.module still blows up for the same reason.

@ches
Copy link
Author

ches commented Jun 15, 2016

Awesome, new release in Homebrew before I even had the chance to try the fix. Thanks!

Not sure if this is at all related, but I seem to have lost all error reporting in 0.6.1:

$ amm -f /dev/null
Loading...
Welcome to the Ammonite Repl 0.6.1
(Scala 2.11.8 Java 1.8.0_92)
@ throw new RuntimeException("wat")
@ throw new IllegalStateException("wat")

Squelching any custom predef there. lastException works, but I'm assuming completely silent failures wasn't a conscious decision? Should I open a new issue for this?

@lihaoyi
Copy link
Member

lihaoyi commented Jun 15, 2016

Yep that was totally not an intentional decision; can you open a new issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants