7
votes

How to debug code in a Scala Future?

I'm using IntelliJ.

Aside from logging everything i don't see how.

Any advise on how to proceed?

EDIT1:

Here is the error i get:

java.lang.IllegalAccessError: tried to access field org.iadb.poolpartyconnector.conceptsrecommendation.RelevantConceptsRecommendationServicePoolPartyImpl$$anonfun$2$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$3.concepts$1 from class org.iadb.poolpartyconnector.conceptsrecommendation.RelevantConceptsRecommendationServicePoolPartyImpl$$anonfun$2$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$3$GeneratedEvaluatorClass$3$1 at org.iadb.poolpartyconnector.conceptsrecommendation.RelevantConceptsRecommendationServicePoolPartyImpl$$anonfun$2$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$3$GeneratedEvaluatorClass$3$1.invoke(FileToCompile0.scala:173) at org.iadb.poolpartyconnector.conceptsrecommendation.RelevantConceptsRecommendationServicePoolPartyImpl$$anonfun$2$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$3.apply(RelevantConceptsRecommendationService.scala:169) at org.iadb.poolpartyconnector.conceptsrecommendation.RelevantConceptsRecommendationServicePoolPartyImpl$$anonfun$2$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$3.apply(RelevantConceptsRecommendationService.scala:166) at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) java.lang.NoSuchFieldError: doc$1 at org.iadb.poolpartyconnector.conceptsrecommendation.RelevantConceptsRecommendationServicePoolPartyImpl$$anonfun$2$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$3$GeneratedEvaluatorClass$4$1.invoke(FileToCompile1.scala:173) at org.iadb.poolpartyconnector.conceptsrecommendation.RelevantConceptsRecommendationServicePoolPartyImpl$$anonfun$2$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$3.apply(RelevantConceptsRecommendationService.scala:169) at org.iadb.poolpartyconnector.conceptsrecommendation.RelevantConceptsRecommendationServicePoolPartyImpl$$anonfun$2$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$3.apply(RelevantConceptsRecommendationService.scala:166) at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

My code:

def filterResultsWithExtractionSettings(conceptResults: ConceptResults): ConceptResults = {

    import system.dispatcher

    val mylist: Iterable[Future[List[Concept]]] = for (fieldSettings <- fieldSettingsList if fieldSettings.maxConceptsExtraction > 0; doc <- conceptResults.document; concepts <- doc.concepts) yield {

       Future {
         val schemefiltered = concepts.withFilter(e => e.conceptSchemes.contains(fieldSettings.scheme)).flatMap(e=> List(e))

          schemefiltered.size match {
           case e if e > fieldSettings.maxConceptsExtraction => schemefiltered.take(fieldSettings.maxConceptsExtraction)
           case _ => schemefiltered
         }
       }

     }

    val res = Await.result(Future.sequence(mylist), Duration.Inf).flatten.toList

    val distinctRes = res.distinct

    conceptResults.copy(document = Some(conceptResults.document.get.copy(concepts = Some(distinctRes))))

}
1
Well, just put a breakpoint on the line...Jean Logeart
IntelliJ's debugger is buggy; I have seen it cause problems like this (IllegalAccessError should never happen in normal code). All I can suggest is using a different debugger and/or submitting a minimal example as a bug report to JetBrains.lmm
I don't suppose you found an answer.Casey

1 Answers

-2
votes

Since you are using IntelliJ, you can add a breakpoint within the Future. You can do that by clicking on the gutter to the left of the line of text you want the breakpoint to be on.

https://www.jetbrains.com/idea/help/creating-breakpoints.html