Skip to content

Conversation

@Damtev
Copy link
Member

@Damtev Damtev commented Jan 17, 2023

Description

Since real implementations of Arrays.copyOf and Arrays.copyOfRange are pretty difficult (due to reflection usage) for the symbolic engine, symbolic implementations are added in this PR. Also, since the mock implementation of Arrays.asList returns an instance of our class UtArrayList, some wrap hacks were added to prevent its appearance as a result of execution.

Fixes #1699 .

Type of Change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

Automated Testing

org.utbot.examples.arrays.CopyOfExampleTest and org.utbot.examples.collections.ListsPart3Test#testAsListExample

Manual Scenario

org.antlr.v4.codegen.model.Recognizer.translateTokenStringsToTarget in Contest Estimator.

Checklist (remove irrelevant options):

  • The change followed the style guidelines of the UTBot project
  • Self-review of the code is passed
  • The change contains enough commentaries, particularly in hard-to-understand areas
  • New documentation is provided or existed one is altered
  • No new warnings
  • New tests have been added
@Damtev Damtev added the comp-symbolic-engine Issue is related to the symbolic execution engine label Jan 17, 2023
@Damtev Damtev requested a review from CaelmBleidd January 17, 2023 14:46
@Damtev Damtev force-pushed the damtev/as_list_fix branch from 73f070b to f7ccac2 Compare January 18, 2023 09:04
@Damtev Damtev enabled auto-merge (squash) January 18, 2023 09:24
@Damtev Damtev disabled auto-merge January 18, 2023 15:24
@Damtev Damtev enabled auto-merge (squash) January 18, 2023 15:42
@Damtev Damtev disabled auto-merge January 18, 2023 15:43
@Damtev Damtev enabled auto-merge (squash) January 18, 2023 15:43
package org.utbot.engine.overrides.stream;

import org.utbot.api.annotation.UtClassMock;
import org.utbot.api.mock.UtMock;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant?

Comment on lines 265 to 266
wrap(UtArrayList::class) { _, addr -> objectValue(LIST_TYPE, addr, ListWrapper(UT_ARRAY_LIST)) },
wrap(UtLinkedList::class) { _, addr -> objectValue(LIST_TYPE, addr, ListWrapper(UT_LINKED_LIST)) },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are they have a list type here? In the wrappers above (e.g. UtStringBuilder and UtStringBuffer) you use concrete types instead of a common interface. Why?

Comment on lines 3239 to 3242
return MethodResult(
newArray,
memoryUpdates = arrayUpdateWithValue(newArray.addr, arrayType, selectArrayExpressionFromMemory(src))
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it. You just created a new array with all unbounded variables. Why is it a copy of the original one? Or you copied the whole original massive even though it might be bigger than a copy? If it is so, please, provide a corresponding comment here

val to = parameters[2] as PrimitiveValue

val originalLength = memory.findArrayLength(original.addr)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a missed NPE check

queuedSymbolicStateUpdates += mkNot(isFromBiggerThanTo).asHardConstraint()

val newLength = Sub(to, from)
val newLengthValue = PrimitiveValue(IntType.v(), newLength)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newLength.toIntValue()

internal val CLASS_REF_SOOT_CLASS: SootClass
get() = Scene.v().getSootClass(CLASS_REF_CLASSNAME)
internal val ARRAYS_SOOT_CLASS: SootClass
get() = Scene.v().getSootClass("java.util.Arrays")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use a java class and its name for consistency with the code below

@Damtev Damtev force-pushed the damtev/as_list_fix branch from f7ccac2 to 9cf6966 Compare January 19, 2023 12:29
@Damtev Damtev requested a review from CaelmBleidd January 19, 2023 13:29
@Damtev Damtev merged commit f7da114 into main Jan 19, 2023
@Damtev Damtev deleted the damtev/as_list_fix branch January 19, 2023 13:32
@alisevych alisevych added the ctg-bug-fix PR is fixing a bug label Jan 20, 2023
@alisevych alisevych added this to the 2023.03 Release milestone Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-symbolic-engine Issue is related to the symbolic execution engine ctg-bug-fix PR is fixing a bug

4 participants