-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed reading by null ref during ensuring enum correctness (#105)
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 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
23 changes: 23 additions & 0 deletions
23
usvm-jvm/src/samples/java/org/usvm/samples/enums/ClassWithEnumField.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,23 @@ | ||
package org.usvm.samples.enums; | ||
|
||
import org.usvm.samples.enums.ClassWithEnum.StatusEnum; | ||
|
||
public class ClassWithEnumField { | ||
// Make it public for simpler extracting in tests | ||
public StatusEnum statusEnum = null; | ||
|
||
public void setStatusEnum(StatusEnum statusEnum) { | ||
this.statusEnum = statusEnum; | ||
} | ||
|
||
public int getStatusCode(int initField) { | ||
ClassWithEnumField classWithEnumField = new ClassWithEnumField(); | ||
if (initField == -1) { | ||
classWithEnumField.setStatusEnum(StatusEnum.READY); | ||
} else if (initField == 1) { | ||
classWithEnumField.setStatusEnum(StatusEnum.ERROR); | ||
} | ||
|
||
return classWithEnumField.statusEnum.code; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
usvm-jvm/src/test/kotlin/org/usvm/samples/enums/ClassWithEnumFieldTest.kt
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,21 @@ | ||
package org.usvm.samples.enums | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.usvm.samples.JavaMethodTestRunner | ||
import org.usvm.samples.enums.ClassWithEnum.StatusEnum | ||
import org.usvm.test.util.checkers.ignoreNumberOfAnalysisResults | ||
import org.usvm.util.isException | ||
import kotlin.math.abs | ||
|
||
class ClassWithEnumFieldTest : JavaMethodTestRunner() { | ||
@Test | ||
fun testEnumFieldCode() { | ||
checkDiscoveredPropertiesWithExceptions( | ||
ClassWithEnumField::getStatusCode, | ||
ignoreNumberOfAnalysisResults, | ||
{ _, i, r -> abs(i) != 1 && r.isException<NullPointerException>() }, | ||
{ _, i, r -> i == -1 && r.getOrThrow() == StatusEnum.READY.code }, | ||
{ _, i, r -> i == 1 && r.getOrThrow() == StatusEnum.ERROR.code }, | ||
) | ||
} | ||
} |