15
15
*/
16
16
package org .openrewrite .staticanalysis ;
17
17
18
- import org .junit .jupiter .api .Disabled ;
19
18
import org .junit .jupiter .api .Nested ;
20
19
import org .junit .jupiter .api .Test ;
21
20
import org .openrewrite .Issue ;
@@ -528,7 +527,6 @@ void test(Object o) {
528
527
}
529
528
530
529
@ Issue ("https://github.com/openrewrite/rewrite/issues/2787" )
531
- @ Disabled
532
530
@ Test
533
531
void nestedPotentiallyConflictingIfs () {
534
532
rewriteRun (
@@ -549,11 +547,11 @@ void test(Object o) {
549
547
"""
550
548
public class A {
551
549
void test(Object o) {
552
- if (o instanceof String string ) {
553
- if (o instanceof String string1 ) {
554
- System.out.println(string1 );
550
+ if (o instanceof String string1 ) {
551
+ if (o instanceof String string ) {
552
+ System.out.println(string );
555
553
}
556
- System.out.println(string );
554
+ System.out.println(string1 );
557
555
}
558
556
}
559
557
}
@@ -562,6 +560,92 @@ void test(Object o) {
562
560
);
563
561
}
564
562
563
+ @ Issue ("https://github.com/openrewrite/rewrite-static-analysis/issues/481" )
564
+ @ Test
565
+ void conflictingWithLocalVariable () {
566
+ rewriteRun (
567
+ //language=java
568
+ java (
569
+ """
570
+ public class Main {
571
+ public class Bar {}
572
+ public class FooBar {}
573
+ public static void main(String[] args) {
574
+ Object o = new Object();
575
+ if (o instanceof Bar) {
576
+ System.out.println(((Bar)o));
577
+ Bar bar = null;
578
+ if (o instanceof FooBar) {
579
+ System.out.println(((FooBar)o));
580
+ Bar bar1 = null;
581
+ }
582
+ }
583
+ }
584
+ }
585
+ """ ,
586
+ """
587
+ public class Main {
588
+ public class Bar {}
589
+ public class FooBar {}
590
+ public static void main(String[] args) {
591
+ Object o = new Object();
592
+ if (o instanceof Bar bar2) {
593
+ System.out.println(bar2);
594
+ Bar bar = null;
595
+ if (o instanceof FooBar fooBar) {
596
+ System.out.println(fooBar);
597
+ Bar bar1 = null;
598
+ }
599
+ }
600
+ }
601
+ }
602
+ """
603
+ )
604
+ );
605
+ }
606
+
607
+ @ Issue ("https://github.com/openrewrite/rewrite-static-analysis/issues/334" )
608
+ @ Test
609
+ void conflictingWithOtherInstanceOf () {
610
+ rewriteRun (
611
+ //language=java
612
+ java (
613
+ """
614
+ public class Main {
615
+ public class Bar {}
616
+ public class FooBar {}
617
+ public static void main(String[] args) {
618
+ Object o = new Object();
619
+ if (o instanceof Bar) {
620
+ System.out.println(((Bar)o));
621
+ if (o instanceof FooBar) {
622
+ System.out.println(((FooBar)o));
623
+ Bar bar1 = null;
624
+ }
625
+ }
626
+ }
627
+ }
628
+ """ ,
629
+ """
630
+ public class Main {
631
+ public class Bar {}
632
+ public class FooBar {}
633
+ public static void main(String[] args) {
634
+ Object o = new Object();
635
+ if (o instanceof Bar bar2) {
636
+ System.out.println(bar2);
637
+ if (o instanceof FooBar bar) {
638
+ System.out.println(bar);
639
+ Bar bar1 = null;
640
+ }
641
+ }
642
+ }
643
+ }
644
+ """
645
+ )
646
+ );
647
+ }
648
+
565
649
@ Test
566
650
void expressionWithSideEffects () {
567
651
rewriteRun (
0 commit comments