Skip to content

Commit

Permalink
Merge pull request scala#7913 from retronym/topic/lambda-deserializer…
Browse files Browse the repository at this point in the history
…-null

Add library support for future fix for scala/bug#11345
  • Loading branch information
adriaanm authored Mar 25, 2019
2 parents 54165d9 + 1e91d8d commit 5eef812
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/library/scala/runtime/LambdaDeserializer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ object LambdaDeserializer {
*/
def deserializeLambda(lookup: MethodHandles.Lookup, cache: java.util.Map[String, MethodHandle],
targetMethodMap: java.util.Map[String, MethodHandle], serialized: SerializedLambda): AnyRef = {
val result = deserializeLambdaOrNull(lookup, cache, targetMethodMap, serialized)
if (result == null) throw new IllegalArgumentException("Illegal lambda deserialization")
else result
}

def deserializeLambdaOrNull(lookup: MethodHandles.Lookup, cache: java.util.Map[String, MethodHandle],
targetMethodMap: java.util.Map[String, MethodHandle], serialized: SerializedLambda): AnyRef = {
assert(targetMethodMap != null)
def slashDot(name: String) = name.replaceAll("/", ".")
val loader = lookup.lookupClass().getClassLoader
Expand Down Expand Up @@ -85,7 +92,7 @@ object LambdaDeserializer {
val implMethod: MethodHandle = if (targetMethodMap.containsKey(key)) {
targetMethodMap.get(key)
} else {
throw new IllegalArgumentException("Illegal lambda deserialization")
return null
}

val flags: Int = LambdaMetafactory.FLAG_SERIALIZABLE
Expand All @@ -101,11 +108,14 @@ object LambdaDeserializer {
}

val factory: MethodHandle = if (cache == null) {
makeCallSite.getTarget
val callSite = makeCallSite
if (callSite == null) return null
callSite.getTarget
} else cache.synchronized{
cache.get(key) match {
case null =>
val callSite = makeCallSite
if (callSite == null) return null
val temp = callSite.getTarget
cache.put(key, temp)
temp
Expand Down

0 comments on commit 5eef812

Please sign in to comment.