Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.openrewrite.staticanalysis;

import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ExpectedToFail;
import org.openrewrite.DocumentExample;
import org.openrewrite.Issue;
import org.openrewrite.test.RecipeSpec;
Expand Down Expand Up @@ -315,4 +316,46 @@ void test(Iterator<String> it) {
)
);
}

@ExpectedToFail("SideEffects.mayHaveSideEffects treats array access as effect-free, so the collapse deletes an access that may throw ArrayIndexOutOfBoundsException")
@Test
void doNotChangeWhenConditionContainsArrayAccess() {
rewriteRun(
//language=java
java(
"""
class Test {
void test(boolean[] flags) {
if (flags[5]) {
System.out.println("hello");
} else {
System.out.println("hello");
}
}
}
"""
)
);
}

@ExpectedToFail("SideEffects.mayHaveSideEffects treats casts as effect-free, so the collapse deletes a cast that may throw ClassCastException, and with it the unboxing that may throw NullPointerException")
@Test
void doNotChangeWhenConditionContainsCast() {
rewriteRun(
//language=java
java(
"""
class Test {
void test(Object o) {
if ((Boolean) o) {
System.out.println("hello");
} else {
System.out.println("hello");
}
}
}
"""
)
);
}
}
Loading