File tree Expand file tree Collapse file tree 1 file changed +15
-13
lines changed
library/src/scala/runtime Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -9,19 +9,21 @@ import scala.annotation.*
99 */
1010object LazyVals {
1111 @ nowarn
12- private [this ] val unsafe : sun.misc.Unsafe =
13- classOf [sun.misc.Unsafe ].getDeclaredFields.nn.find { field =>
14- field.nn.getType == classOf [sun.misc.Unsafe ] && {
15- field.nn.setAccessible(true )
16- true
17- }
18- }
19- .map(_.nn.get(null ).asInstanceOf [sun.misc.Unsafe ])
20- .getOrElse {
21- throw new ExceptionInInitializerError {
22- new IllegalStateException (" Can't find instance of sun.misc.Unsafe" )
23- }
24- }
12+ private [this ] val unsafe : sun.misc.Unsafe = {
13+ def throwInitializationException () =
14+ throw new ExceptionInInitializerError (
15+ new IllegalStateException (" Can't find instance of sun.misc.Unsafe" )
16+ )
17+ try
18+ val unsafeField = classOf [sun.misc.Unsafe ].getDeclaredField(" theUnsafe" ).nn
19+ if unsafeField.getType == classOf [sun.misc.Unsafe ] then
20+ unsafeField.setAccessible(true )
21+ unsafeField.get(null ).asInstanceOf [sun.misc.Unsafe ]
22+ else
23+ throwInitializationException()
24+ catch case _ : NoSuchFieldException =>
25+ throwInitializationException()
26+ }
2527
2628 private [this ] val base : Int = {
2729 val processors = java.lang.Runtime .getRuntime.nn.availableProcessors()
You can’t perform that action at this time.
0 commit comments