@@ -58,25 +58,17 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
5858 // `ScalaRunTime.replStringOf`. Probe for new API without extraneous newlines.
5959 // For old API, try to clean up extraneous newlines by stripping suffix and maybe prefix newline.
6060 val scalaRuntime = Class .forName(" scala.runtime.ScalaRunTime" , true , myClassLoader)
61+ val renderer = " stringOf" // was: replStringOf
6162 try {
62- val meth = scalaRuntime.getMethod(" replStringOf " , classOf [Object ], classOf [Int ], classOf [Boolean ])
63+ val meth = scalaRuntime.getMethod(renderer , classOf [Object ], classOf [Int ], classOf [Boolean ])
6364 val truly = java.lang.Boolean .TRUE
6465
6566 (value : Object ) => meth.invoke(null , value, Integer .valueOf(MaxStringElements ), truly).asInstanceOf [String ]
6667 } catch {
6768 case _ : NoSuchMethodException =>
68- val meth = scalaRuntime.getMethod(" replStringOf" , classOf [Object ], classOf [Int ])
69-
70- (value : Object ) => {
71- val res = meth.invoke(null , value, Integer .valueOf(MaxStringElements )).asInstanceOf [String ]
72- val len = res.length()
73- if len == 0 || res.charAt(len- 1 ) != '\n ' then
74- res
75- else if len == 1 || res.charAt(0 ) != '\n ' then
76- res.substring(0 , len- 1 )
77- else
78- res.substring(1 , len- 1 )
79- }
69+ val meth = scalaRuntime.getMethod(renderer, classOf [Object ], classOf [Int ])
70+
71+ (value : Object ) => meth.invoke(null , value, Integer .valueOf(MaxStringElements )).asInstanceOf [String ]
8072 }
8173 }
8274 myClassLoader
@@ -99,7 +91,8 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
9991 private [repl] def replStringOf (value : Object )(using Context ): String = {
10092 assert(myReplStringOf != null ,
10193 " replStringOf should only be called on values creating using `classLoader()`, but `classLoader()` has not been called so far" )
102- truncate(myReplStringOf(value))
94+ val res = myReplStringOf(value)
95+ if res == null then " null // non-null reference has null-valued toString" else truncate(res)
10396 }
10497
10598 /** Load the value of the symbol using reflection.
0 commit comments