applctv / gcp-scala-datastore

Scala wrapper to Google Cloud Datastore operations
15 stars 16 forks source link

Example in README throws java.lang.InternalError: Malformed class name #22

Closed jdugan1024 closed 6 years ago

jdugan1024 commented 6 years ago

Hello. This package looks useful and I appreciate the effort that has gone into it so far. Thanks!

I'm trying the example in the README in an sbt console with 1.0-rc8, however it is throwing java.lang.InternalError: Malformed class name. I've included a transcript below. Any idea what's happening?

I am able to use the Java example from the same console and it works fine. I also included the crude translation into Scala of that example below.

Thanks for any insight you can shed on this issue.

> console
[info] Starting scala interpreter...
[info]
Welcome to Scala 2.11.11 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_77).
Type in expressions for evaluation. Or try :help.

scala> import io.applicative.datastore.{BaseEntity, DatastoreService}
import io.applicative.datastore.{BaseEntity, DatastoreService}

scala> import io.applicative.datastore.query._
import io.applicative.datastore.query._

scala>

scala> import scala.concurrent.Future
import scala.concurrent.Future

scala> import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.ExecutionContext.Implicits.global

scala>

scala> // Sample model class

scala> case class Item(id: Long, name: String, price: Double, size: Int, brand: Option[String]) extends BaseEntity
defined class Item

scala>

scala> val item = Item(1, "foo", 20.0, 2, None)
item: Item = Item(1,foo,20.0,2,None)

scala>

scala> // Save

scala> DatastoreService.add[Item](item)
res0: scala.concurrent.Future[Item] = Future(<not completed>)
java.lang.InternalError: Malformed class name
    at java.lang.Class.getSimpleName(Class.java:1330)
    at java.lang.Class.getCanonicalName(Class.java:1399)
    at io.applicative.datastore.DatastoreService$.io$applicative$datastore$DatastoreService$$getKind(DatastoreService.scala:198)
    at io.applicative.datastore.DatastoreService$$anonfun$add$1.apply(DatastoreService.scala:46)
    at io.applicative.datastore.DatastoreService$$anonfun$add$1.apply(DatastoreService.scala:44)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
    at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
    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)

scala>

Java example:

// Imports the Google Cloud client library
import com.google.cloud.datastore.Datastore;
import com.google.cloud.datastore.DatastoreOptions;
import com.google.cloud.datastore.Entity;
import com.google.cloud.datastore.Key;

val datastore = DatastoreOptions.getDefaultInstance().getService();

val kind = "Task";
val name = "sampletask1";
val taskKey = datastore.newKeyFactory().setKind(kind).newKey(name);

val task = Entity.newBuilder(taskKey).set("description", "Buy milk").set("priority", 1).build()

datastore.put(task);
a-panchenko commented 6 years ago

Hello @jdugan1024 This looks weird. I'll check it.

a-panchenko commented 6 years ago

@jdugan1024 This seems to be a kind of bug of Scala REPL and Java itself. Do you really need to use the library in REPL?

danosipov commented 6 years ago

May be related to https://issues.scala-lang.org/browse/SI-5425 since REPL nests classes

jdugan1024 commented 6 years ago

I don't need to run this in the REPL, I was just using the REPL to try it out. I put the code in a file and ran it that way and it works fine.

Thanks for the clarification, I had no idea the Scala REPL has this problem.

I appreciate your quick turnaround on this.