error reading Scala signature

791 views
Skip to first unread message

Andreas Joseph Krogh

unread,
Nov 19, 2013, 4:41:08 AM11/19/13
to scala...@googlegroups.com
Hi.
 
Sometimes I get Exceptions like these  when using reflection:
 
java.lang.RuntimeException: error reading Scala signature of no.officenet.origo.calendar.domain.model.calendarentry.CalendarEntry: value Predef is not a package
        at scala.reflect.internal.pickling.UnPickler.unpickle(UnPickler.scala:45)
        at scala.reflect.runtime.JavaMirrors$JavaMirror.unpickleClass(JavaMirrors.scala:565)
        at scala.reflect.runtime.SymbolLoaders$TopClassCompleter.complete(SymbolLoaders.scala:32)
        at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1229)
        at scala.reflect.internal.Types$TypeRef.decls(Types.scala:2436)
        at scala.reflect.internal.Types$Type.findDecl(Types.scala:1059)
        at scala.reflect.internal.Types$Type.decl(Types.scala:646)
        at scala.reflect.internal.Types$TypeApiImpl.declaration(Types.scala:299)
        at scala.reflect.internal.Types$TypeApiImpl.declaration(Types.scala:298)
        at no.officenet.origo.core.infrastructure.validation.OrigoValidator.resolveValue(OrigoValidator.scala:75)
 
AND
 
scala.reflect.runtime.ReflectError: value Predef is not a package
        at scala.reflect.runtime.JavaMirrors$JavaMirror.scala$reflect$runtime$JavaMirrors$$makeScalaPackage(JavaMirrors.scala:912)
        at scala.reflect.runtime.JavaMirrors$class.missingHook(JavaMirrors.scala:1296)
        at scala.reflect.runtime.JavaUniverse.missingHook(JavaUniverse.scala:12)
        at scala.reflect.internal.Mirrors$RootsBase.universeMissingHook(Mirrors.scala:77)
        at scala.reflect.internal.Mirrors$RootsBase.missingHook(Mirrors.scala:79)
        at scala.reflect.internal.pickling.UnPickler$Scan.readExtSymbol$1(UnPickler.scala:226)
        at scala.reflect.internal.pickling.UnPickler$Scan.readSymbol(UnPickler.scala:250)
        at scala.reflect.internal.pickling.UnPickler$Scan.readSymbolRef(UnPickler.scala:783)
        at scala.reflect.internal.pickling.UnPickler$Scan.readExtSymbol$1(UnPickler.scala:200)
        at scala.reflect.internal.pickling.UnPickler$Scan.readSymbol(UnPickler.scala:250)
        at scala.reflect.internal.pickling.UnPickler$Scan.readSymbolRef(UnPickler.scala:783)
        at scala.reflect.internal.pickling.UnPickler$Scan.readType(UnPickler.scala:346)
        at scala.reflect.internal.pickling.UnPickler$Scan$LazyTypeRef$$anonfun$34.apply(UnPickler.scala:855)
        at scala.reflect.internal.pickling.UnPickler$Scan$LazyTypeRef$$anonfun$34.apply(UnPickler.scala:855)
        at scala.reflect.internal.pickling.UnPickler$Scan.at(UnPickler.scala:171)
        at scala.reflect.internal.pickling.UnPickler$Scan$LazyTypeRef.complete(UnPickler.scala:855)
        at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1229)
        at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1365)
        at scala.reflect.internal.Symbols$Symbol.annotations(Symbols.scala:1572)
        at scala.reflect.internal.Symbols$Symbol.addAnnotation(Symbols.scala:1591)
        at scala.reflect.internal.pickling.UnPickler$Scan.readSymbolAnnotation(UnPickler.scala:491)
        at scala.reflect.internal.pickling.UnPickler$Scan.run(UnPickler.scala:88)
        at scala.reflect.internal.pickling.UnPickler.unpickle(UnPickler.scala:37)
        at scala.reflect.runtime.JavaMirrors$JavaMirror.unpickleClass(JavaMirrors.scala:565)
        at scala.reflect.runtime.SymbolLoaders$TopClassCompleter.complete(SymbolLoaders.scala:32)
        at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1229)
        at scala.reflect.internal.Types$TypeRef.decls(Types.scala:2436)
        at scala.reflect.internal.Types$Type.findDecl(Types.scala:1059)
        at scala.reflect.internal.Types$Type.decl(Types.scala:646)
        at scala.reflect.internal.Types$TypeApiImpl.declaration(Types.scala:299)
        at scala.reflect.internal.Types$TypeApiImpl.declaration(Types.scala:298)
        at no.officenet.origo.core.infrastructure.validation.OrigoValidator.resolveValue(OrigoValidator.scala:75)
 
OrigoValidator.resolveValue looks like this:
 
val mirror = currentMirror
override def resolveValue(ctx: FieldContext, validatedObject: scala.Any): AnyRef = {
        val field: Field = ctx.getField
        if (!field.isAccessible) {
                field.setAccessible(true)
        }
        val c = field.getDeclaringClass
        val classMirror = mirror.classSymbol(c)
        val fieldType = mirror.classSymbol(field.getType).toType
        val im = mirror.reflect(validatedObject)
        (classMirror.toType.declaration(newTermName(field.getName)) match {
                case ms: MethodSymbol => Some(ms)
                case _ => None
        }).filter(_.returnType == fieldType).map{m =>
                val mm = im.reflectMethod(m)
                mm.apply().asInstanceOf[AnyRef]
        }.getOrElse(field.get(validatedObject))
}
 
Having this method synchronized will degrade performance a lot as it's part of validating-code in my domain-layer..
 
Any workarounds?
 
Thanks.
 
--
Andreas Joseph Krogh <and...@officenet.no>      mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc

Eugene Burmako

unread,
Nov 19, 2013, 4:44:44 AM11/19/13
to Andreas Joseph Krogh, scala-user
It indeed looks like the errors might be caused by the reflection sync problem, but I'd like to learn more details. Does making this method synchronized fix the problem? Could you provide a minimized reproduction?


--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Andreas Joseph Krogh

unread,
Nov 19, 2013, 4:50:45 AM11/19/13
to scala...@googlegroups.com
På tirsdag 19. november 2013 kl. 10:44:44, skrev Eugene Burmako <eugene....@epfl.ch>:
It indeed looks like the errors might be caused by the reflection sync problem, but I'd like to learn more details. Does making this method synchronized fix the problem? Could you provide a minimized reproduction?
 
It's challenging because these errors seldom occur. The pattern seems to be that when it occurs it seems to be after a rebuild->redeploy of my app.
 
I'll see if I can come up with a reproduceable case.
 
Is synchronizing on the runtime-mirror the advice so far, like this?
override def resolveValue(ctx: FieldContext, validatedObject: scala.Any): AnyRef = {
        val field: Field = ctx.getField
        if (!field.isAccessible) {
                field.setAccessible(true)
        }
        val c = field.getDeclaringClass
        mirror.synchronized {
                val classMirror = mirror.classSymbol(c)
                val fieldType = mirror.classSymbol(field.getType).toType
                val im = mirror.reflect(validatedObject)
                (classMirror.toType.declaration(newTermName(field.getName)) match {
                        case ms: MethodSymbol => Some(ms)
                        case _ => None
                }).filter(_.returnType == fieldType).map{m =>
                        val mm = im.reflectMethod(m)
                        mm.apply().asInstanceOf[AnyRef]
                }.getOrElse(field.get(validatedObject))
        }
}

Thanks.

Eugene Burmako

unread,
Nov 19, 2013, 4:54:01 AM11/19/13
to Andreas Joseph Krogh, scala-user
What you would ideally want is to prevent any runtime reflection from going on in parallel with resolveValue, i.e. you would need to guard every point in your program that can execute simultaneously with resolveValue with the same synchronized. Sorry for this being so convoluted, but on the bright side, I think we've got the reflection sync issue handled in 2.11.0-M7.


 

--

Andreas Joseph Krogh

unread,
Nov 19, 2013, 5:09:50 AM11/19/13
to scala...@googlegroups.com
På tirsdag 19. november 2013 kl. 10:54:01, skrev Eugene Burmako <eugene....@epfl.ch>:
What you would ideally want is to prevent any runtime reflection from going on in parallel with resolveValue, i.e. you would need to guard every point in your program that can execute simultaneously with resolveValue with the same synchronized. Sorry for this being so convoluted, but on the bright side, I think we've got the reflection sync issue handled in 2.11.0-M7.
 
This is the only place in my app where runtime reflection is used, so syncing on 'mirror' in resolveValue should be fine right?
Using 2.11 is not an option yet sorry:-)
Reply all
Reply to author
Forward
0 new messages