Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Disabled NPE checks for non-public fields in non-application classes …
…by default
  • Loading branch information
Damtev committed Jul 7, 2022
commit 7cf9b50e025651cd053d9693590aaaba475735bb
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,22 @@ object UtSettings {
var enableMachineLearningModule by getBooleanProperty(true)

/**
* Options below regulate which NullPointerExceptions check should be performed.
* Options below regulate which [NullPointerException] check should be performed.
*
* Set an option in true if you want to perform NPE check in the corresponding situations, otherwise set false.
*/
var checkNpeInNestedMethods by getBooleanProperty(true)
var checkNpeInNestedNotPrivateMethods by getBooleanProperty(false)
var checkNpeForFinalFields by getBooleanProperty(false)

/**
* This option determines whether should we generate [NullPointerException] checks for final or non-public fields
Comment thread
Damtev marked this conversation as resolved.
Outdated
* in non-application classes. Set by true, this option highly decreases test's readability in some cases
* because of using reflection API for setting final/non-public fields in non-application classes.
*
* NOTE: default false value loses some executions with NPE in system classes, but often most of these executions
* are not expected by user.
*/
var maximizeCoverageUsingReflection by getBooleanProperty(false)

/**
* Activate or deactivate substituting static fields values set in static initializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ import org.utbot.engine.symbolic.asSoftConstraint
import org.utbot.engine.symbolic.asAssumption
import org.utbot.engine.symbolic.asUpdate
import org.utbot.engine.util.mockListeners.MockListener
import org.utbot.engine.util.mockListeners.MockListenerController
import org.utbot.engine.util.statics.concrete.associateEnumSootFieldsWithConcreteValues
import org.utbot.engine.util.statics.concrete.isEnumAffectingExternalStatics
import org.utbot.engine.util.statics.concrete.isEnumValuesFieldName
Expand All @@ -116,7 +115,7 @@ import org.utbot.engine.util.statics.concrete.makeEnumStaticFieldsUpdates
import org.utbot.engine.util.statics.concrete.makeSymbolicValuesFromEnumConcreteValues
import org.utbot.framework.PathSelectorType
import org.utbot.framework.UtSettings
import org.utbot.framework.UtSettings.checkNpeForFinalFields
import org.utbot.framework.UtSettings.maximizeCoverageUsingReflection
import org.utbot.framework.UtSettings.checkSolverTimeoutMillis
import org.utbot.framework.UtSettings.enableFeatureProcess
import org.utbot.framework.UtSettings.pathSelectorStepsLimit
Expand Down Expand Up @@ -339,7 +338,7 @@ class UtBotSymbolicEngine(

private val classUnderTest: ClassId = methodUnderTest.clazz.id

private val mocker: Mocker = Mocker(mockStrategy, classUnderTest, hierarchy, chosenClassesToMockAlways, MockListenerController(controller))
private val mocker: Mocker = Mocker(mockStrategy, classUnderTest, hierarchy, chosenClassesToMockAlways)

private val statesForConcreteExecution: MutableList<ExecutionState> = mutableListOf()

Expand Down Expand Up @@ -2233,14 +2232,22 @@ class UtBotSymbolicEngine(
}

// See docs/SpeculativeFieldNonNullability.md for details
if (field.isFinal && field.declaringClass.isLibraryClass && !checkNpeForFinalFields) {
markAsSpeculativelyNotNull(createdField.addr)
}
checkAndMarkLibraryFieldSpeculativelyNotNull(field, createdField)
}

return createdField
}

private fun checkAndMarkLibraryFieldSpeculativelyNotNull(field: SootField, createdField: SymbolicValue) {
if (maximizeCoverageUsingReflection || !field.declaringClass.isLibraryClass) {
Comment thread
Damtev marked this conversation as resolved.
Outdated
return
}

if (field.isFinal || !field.isPublic) {
markAsSpeculativelyNotNull(createdField.addr)
}
}

private fun createArray(pName: String, type: ArrayType): ArrayValue {
val addr = UtAddrExpression(mkBVConst(pName, UtIntSort))
return createArray(addr, type, useConcreteType = false)
Expand Down