GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fixed NPE for processing static field as first statement in MUT by Damtev · Pull Request #433 · UnitTestBot/UTBotJava

Fixed NPE for processing static field as first statement in MUT #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Damtev merged 1 commit into main from damtev/concrete_static_field_fix
Jul 7, 2022

Uh oh!

There was an error while loading. Please reload this page.

Merged

Fixed NPE for processing static field as first statement in MUT #433

Changes from all commits
Commits
Show all changes
1 commit
Select commit
5b6bf16
Fixed NPE for processing static field as first statement in MUT
Damtev Jul 6, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

95 changes: 56 additions & 39 deletions 95 utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -906,23 +906,34 @@ class UtBotSymbolicEngine(
// Gets concrete value, converts to symbolic value
val declaringClass = field.declaringClass

val (edge, updates) = if (declaringClass.isEnum) {
val updates = if (declaringClass.isEnum) {
makeConcreteUpdatesForEnums(fieldId, declaringClass, stmt)
} else {
makeConcreteUpdatesForNonEnumStaticField(field, fieldId, declaringClass)
makeConcreteUpdatesForNonEnumStaticField(field, fieldId, declaringClass, stmt)
}

// a static initializer can be the first statement in method so there will be no last edge
// for example, as it is during Enum::values method analysis:
// public static ClassWithEnum$StatusEnum[] values()
// {
// ClassWithEnum$StatusEnum[] $r0, $r2;
// java.lang.Object $r1;

// $r0 = <ClassWithEnum$StatusEnum: ClassWithEnum$StatusEnum[] $VALUES>;
val edge = environment.state.lastEdge ?: globalGraph.succ(stmt)

val newState = environment.state.updateQueued(edge, updates)
pathSelector.offer(newState)

return true
}

@Suppress("UnnecessaryVariable")
private fun makeConcreteUpdatesForEnums(
fieldId: FieldId,
declaringClass: SootClass,
stmt: Stmt
): Pair<Edge, SymbolicStateUpdate> {
): SymbolicStateUpdate {
val type = declaringClass.type
val jClass = type.id.jClass

Expand Down Expand Up @@ -966,46 +977,21 @@ class UtBotSymbolicEngine(
meaningfulStaticFields = meaningfulStaticFields.map { it.first.fieldId }.toPersistentSet()
)

var allUpdates = staticFieldUpdates + nonStaticFieldsUpdates + initializedStaticFieldsMemoryUpdate

// we need to make locals update if it is an assignment statement
// for enums we have only two types for assignment with enums — enum constant or $VALUES field
// for example, a jimple body for Enum::values method starts with the following lines:
// public static ClassWithEnum$StatusEnum[] values()
// {
// ClassWithEnum$StatusEnum[] $r0, $r2;
// java.lang.Object $r1;
// $r0 = <ClassWithEnum$StatusEnum: ClassWithEnum$StatusEnum[] $VALUES>;
// $r1 = virtualinvoke $r0.<java.lang.Object: java.lang.Object clone()>();

// so, we have to make an update for the local $r0
if (stmt is JAssignStmt) {
val local = stmt.leftOp as JimpleLocal
val localUpdate = localMemoryUpdate(
local.variable to curFieldSymbolicValueForLocalVariable
)

allUpdates += localUpdate
}

// enum static initializer can be the first statement in method so there will be no last edge
// for example, as it is during Enum::values method analysis:
// public static ClassWithEnum$StatusEnum[] values()
// {
// ClassWithEnum$StatusEnum[] $r0, $r2;
// java.lang.Object $r1;

// $r0 = <ClassWithEnum$StatusEnum: ClassWithEnum$StatusEnum[] $VALUES>;
val edge = environment.state.lastEdge ?: globalGraph.succ(stmt)
val allUpdates = staticFieldUpdates +
nonStaticFieldsUpdates +
initializedStaticFieldsMemoryUpdate +
createConcreteLocalValueUpdate(stmt, curFieldSymbolicValueForLocalVariable)

return edge to allUpdates
return allUpdates
}

@Suppress("UnnecessaryVariable")
private fun makeConcreteUpdatesForNonEnumStaticField(
field: SootField,
fieldId: FieldId,
declaringClass: SootClass
): Pair<Edge, SymbolicStateUpdate> {
declaringClass: SootClass,
stmt: Stmt
): SymbolicStateUpdate {
val concreteValue = extractConcreteValue(field, declaringClass)
val (symbolicResult, symbolicStateUpdate) = toMethodResult(concreteValue, field.type)
val symbolicValue = (symbolicResult as SymbolicSuccess).value
Expand All @@ -1019,9 +1005,40 @@ class UtBotSymbolicEngine(
field = field,
value = valueToExpression(symbolicValue, field.type)
)
val allUpdates = symbolicStateUpdate + initializedFieldUpdate + objectUpdate
val allUpdates = symbolicStateUpdate +
initializedFieldUpdate +
objectUpdate +
createConcreteLocalValueUpdate(stmt, symbolicValue)

return allUpdates
}

/**
* Creates a local update consisting [symbolicValue] for a local variable from [stmt] in case [stmt] is [JAssignStmt].
*/
private fun createConcreteLocalValueUpdate(
stmt: Stmt,
symbolicValue: SymbolicValue?,
): LocalMemoryUpdate {
// we need to make locals update if it is an assignment statement
// for enums we have only two types for assignment with enums — enum constant or $VALUES field
// for example, a jimple body for Enum::values method starts with the following lines:
// public static ClassWithEnum$StatusEnum[] values()
// {
// ClassWithEnum$StatusEnum[] $r0, $r2;
// java.lang.Object $r1;
// $r0 = <ClassWithEnum$StatusEnum: ClassWithEnum$StatusEnum[] $VALUES>;
// $r1 = virtualinvoke $r0.<java.lang.Object: java.lang.Object clone()>();

// so, we have to make an update for the local $r0

return environment.state.lastEdge!! to allUpdates
return if (stmt is JAssignStmt) {
val local = stmt.leftOp as JimpleLocal

localMemoryUpdate(local.variable to symbolicValue)
} else {
LocalMemoryUpdate()
}
}

// Some fields are inaccessible with reflection, so we have to instantiate it by ourselves.
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.