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

RuntimeException from REPL predef only after compilation is cached #472

ches opened this issue Sep 15, 2016 · 5 comments

RuntimeException from REPL predef only after compilation is cached #472

ches opened this issue Sep 15, 2016 · 5 comments


Copy link

@ches ches commented Sep 15, 2016

I've just upgraded to 0.7.6 and adapted my for changes like interp namespacing, etc.

When I freshly rm -rf ~/.ammonite/cache and run amm, everything compiles and my predef works. Once I quit that REPL instance, it won't start again. Wiping the cache again fixes it, once.

My ~/.ammonite/ looks like this:

repl.prompt() = "\n> "

// Show compiler warnings
repl.compiler.settings.nowarnings.value = false

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

And the backtrace on every amm run after the first looks like this:

$ amm
Exception in thread "main" java.lang.RuntimeException: Error during Predef:
    at ammonite.runtime.Interpreter$$anonfun$10.apply(Interpreter.scala:138)
    at ammonite.runtime.Interpreter$$anonfun$10.apply(Interpreter.scala:118)
    at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:733)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:732)
    at ammonite.runtime.Interpreter.<init>(Interpreter.scala:118)
    at ammonite.repl.Repl.<init>(Repl.scala:43)
    at ammonite.Main.instantiateRepl(Main.scala:61)
    at ammonite.Main$$anonfun$main$1$$anonfun$apply$1.apply(Main.scala:249)
    at ammonite.Main$.ammonite$Main$$ifContinually$1(Main.scala:228)
    at ammonite.Main$$anonfun$main$1.apply(Main.scala:230)
    at ammonite.Main$$anonfun$main$1.apply(Main.scala:230)
    at scala.Option.foreach(Option.scala:257)
    at ammonite.Main$.main(Main.scala:230)
    at ammonite.Main.main(Main.scala)
Caused by: java.lang.NullPointerException
    at ammonite.repl.ReplApiImpl.compiler(ApiImpls.scala:117)
    at ammonite.predef.LoadedPredef$.<init>(
    at ammonite.predef.LoadedPredef$.<clinit>(
    at ammonite.predef.LoadedPredef.$main(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at ammonite.runtime.Evaluator$$anon$1.evalMain(Evaluator.scala:106)
    at ammonite.runtime.Evaluator$$anon$1$$anonfun$evalCachedClassFiles$1$$anonfun$apply$6.apply(Evaluator.scala:172)
    at ammonite.runtime.Evaluator$$anon$1$$anonfun$evalCachedClassFiles$1$$anonfun$apply$6.apply(Evaluator.scala:172)
    at ammonite.util.Res$
    at ammonite.runtime.Evaluator$$anon$1$$anonfun$evalCachedClassFiles$1.apply(Evaluator.scala:172)
    at ammonite.runtime.Evaluator$$anon$1$$anonfun$evalCachedClassFiles$1.apply(Evaluator.scala:168)
    at ammonite.util.Res$$anonfun$1.apply(Res.scala:33)
    at ammonite.util.Res$$anonfun$1.apply(Res.scala:30)
    at scala.collection.TraversableOnce$$anonfun$foldLeft$1.apply(TraversableOnce.scala:157)
    at scala.collection.TraversableOnce$$anonfun$foldLeft$1.apply(TraversableOnce.scala:157)
    at scala.collection.Iterator$class.foreach(Iterator.scala:893)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1336)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
    at scala.collection.TraversableOnce$class.foldLeft(TraversableOnce.scala:157)
    at scala.collection.AbstractTraversable.foldLeft(Traversable.scala:104)
    at ammonite.util.Res$.map(Res.scala:30)
    at ammonite.runtime.Evaluator$$anon$1.evalCachedClassFiles(Evaluator.scala:168)
    at ammonite.runtime.Interpreter.processModule(Interpreter.scala:400)
    at ammonite.runtime.Interpreter$$anonfun$10.apply(Interpreter.scala:121)
    ... 15 more
Copy link

@lihaoyi lihaoyi commented Oct 4, 2016

Ah, yeah, the "don't initialize compiler until needed" logic probably made this break.

The solution would be to add a call to

if (interp.compiler == null) interp.init()

Into this function:

@ches if you have time, check out the repo and see if this fixes your problem. If it works send a PR 😄

Copy link

@lihaoyi lihaoyi commented Nov 15, 2016

A better solution would be to make interp.compiler a Future[() => Global] instead of just a Global; that would let people do

for(c <- interp.compiler) c().settings.nowarnings.value = ...

That would make our compiler-setup code properly trigger the first time the compiler gets initialized, without forcing initialisation of the compiler when not necessary. The Future[() => Global] type would accurately represent the fact that you could get back a different compiler each time, but cannot get one at all until the compiler is initialised for the first time and the Future completes

Copy link

@ches ches commented Nov 15, 2016

The first fix you suggested did solve the issue. I started to look around for whether there are tests around this area of code but I have essentially no familiarity with the codebase and running the full suite was proving to be an exercise in patience, I roamed off to other things 😅

I'll take another look at your second suggestion when I can devote some time to really understanding what I'm doing in there…

Copy link

@lihaoyi lihaoyi commented May 20, 2017

Fixed by c6a282d

@lihaoyi lihaoyi closed this May 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants