@@ -58,25 +58,17 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
58
58
// `ScalaRunTime.replStringOf`. Probe for new API without extraneous newlines.
59
59
// For old API, try to clean up extraneous newlines by stripping suffix and maybe prefix newline.
60
60
val scalaRuntime = Class .forName(" scala.runtime.ScalaRunTime" , true , myClassLoader)
61
+ val renderer = " stringOf" // was: replStringOf
61
62
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 ])
63
64
val truly = java.lang.Boolean .TRUE
64
65
65
66
(value : Object ) => meth.invoke(null , value, Integer .valueOf(MaxStringElements ), truly).asInstanceOf [String ]
66
67
} catch {
67
68
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 ]
80
72
}
81
73
}
82
74
myClassLoader
@@ -99,7 +91,8 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
99
91
private [repl] def replStringOf (value : Object )(using Context ): String = {
100
92
assert(myReplStringOf != null ,
101
93
" 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)
103
96
}
104
97
105
98
/** Load the value of the symbol using reflection.
0 commit comments