@@ -545,4 +545,100 @@ public void testNumberCasts() {
545
545
expectScriptThrows (ClassCastException .class , () -> exec ("Number o = new ArrayList(); ArrayList b = o;" ));
546
546
expectScriptThrows (ClassCastException .class , () -> exec ("Number o = new ArrayList(); ArrayList b = (ArrayList)o;" ));
547
547
}
548
+
549
+ public void testStringCasts () {
550
+ exec ("String o = 'string'; Object n = o;" );
551
+ exec ("String o = null; Object n = o;" );
552
+ exec ("String o = 'string'; Object n = (Object)o;" );
553
+ exec ("String o = null; Object n = (Object)o;" );
554
+
555
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Number n = o;" ));
556
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Number n = o;" ));
557
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Number n = (String)o;" ));
558
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Number n = (String)o;" ));
559
+
560
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; boolean b = o;" ));
561
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; boolean b = o;" ));
562
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; boolean b = (boolean)o;" ));
563
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; boolean b = (boolean)o;" ));
564
+
565
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; byte b = o;" ));
566
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; byte b = o;" ));
567
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; byte b = (byte)o;" ));
568
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; byte b = (byte)o;" ));
569
+
570
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; short b = o;" ));
571
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; short b = o;" ));
572
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; short b = (short)o;" ));
573
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; short b = (short)o;" ));
574
+
575
+ assertEquals ('s' , exec ("String s = 's'; (char)s" ));
576
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; char b = o;" ));
577
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; char b = o;" ));
578
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; char b = (char)o;" ));
579
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; char b = (char)o;" ));
580
+
581
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; int b = o;" ));
582
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; int b = o;" ));
583
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; int b = (int)o;" ));
584
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; int b = (int)o;" ));
585
+
586
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; long b = o;" ));
587
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; long b = o;" ));
588
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; long b = (long)o;" ));
589
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; long b = (long)o;" ));
590
+
591
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; float b = o;" ));
592
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; float b = o;" ));
593
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; float b = (float)o;" ));
594
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; float b = (float)o;" ));
595
+
596
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; double b = o;" ));
597
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; double b = o;" ));
598
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; double b = (double)o;" ));
599
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; double b = (double)o;" ));
600
+
601
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Boolean b = o;" ));
602
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Boolean b = o;" ));
603
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Boolean b = (Boolean)o;" ));
604
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Boolean b = (Boolean)o;" ));
605
+
606
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Byte b = o;" ));
607
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Byte b = o;" ));
608
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Byte b = (Byte)o;" ));
609
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Byte b = (Byte)o;" ));
610
+
611
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Short b = o;" ));
612
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Short b = o;" ));
613
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Short b = (Short)o;" ));
614
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Short b = (Short)o;" ));
615
+
616
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Character b = o;" ));
617
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Character b = o;" ));
618
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Character b = (Character)o;" ));
619
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Character b = (Character)o;" ));
620
+
621
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Integer b = o;" ));
622
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Integer b = o;" ));
623
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Integer b = (Integer)o;" ));
624
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Integer b = (Integer)o;" ));
625
+
626
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Long b = o;" ));
627
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Long b = o;" ));
628
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Long b = (Long)o;" ));
629
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Long b = (Long)o;" ));
630
+
631
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Float b = o;" ));
632
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Float b = o;" ));
633
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Float b = (Float)o;" ));
634
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Float b = (Float)o;" ));
635
+
636
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Double b = o;" ));
637
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Double b = o;" ));
638
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; Double b = (Double)o;" ));
639
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = null; Double b = (Double)o;" ));
640
+
641
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; ArrayList b = o;" ));
642
+ expectScriptThrows (ClassCastException .class , () -> exec ("String o = 'string'; ArrayList b = (ArrayList)o;" ));
643
+ }
548
644
}
0 commit comments