-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: checks for field init reorder (#1599)
- Loading branch information
Showing
6 changed files
with
83 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInitNegative.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package jadx.tests.integration.others; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
/** | ||
* Negative case for field initialization move (#1599). | ||
* Can't reorder with other instance methods. | ||
*/ | ||
public class TestFieldInitNegative extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
StringBuilder sb; | ||
int field; | ||
|
||
public TestCls() { | ||
initBuilder(new StringBuilder("sb")); | ||
this.field = initField(); | ||
this.sb.append(this.field); | ||
} | ||
|
||
private void initBuilder(StringBuilder sb) { | ||
this.sb = sb; | ||
} | ||
|
||
private int initField() { | ||
return sb.length(); | ||
} | ||
|
||
public String getStr() { | ||
return sb.toString(); | ||
} | ||
|
||
public void check() { | ||
assertThat(new TestCls().getStr()).isEqualTo("sb2"); // no NPE | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
assertThat(getClassNode(TestCls.class)) | ||
.code() | ||
.doesNotContain("int field = initField();") | ||
.containsOne("this.field = initField();"); | ||
} | ||
} |