@@ -776,8 +776,16 @@ class Traverser(
776776
777777 private fun TraversalContext.skipVerticesForThrowableCreation (current : JAssignStmt ) {
778778 val rightType = current.rightOp.type as RefType
779- val exceptionType = Scene .v().getSootClass(rightType.className).type
780- val createdException = createObject(findNewAddr(), exceptionType, true )
779+ val exceptionType = Scene .v().getRefType(rightType.className)
780+ val mockInfoGenerator = UtMockInfoGenerator { mockAddr ->
781+ UtNewInstanceMockInfo (exceptionType.id, mockAddr, environment.method.declaringClass.id)
782+ }
783+ val createdException = createObject(
784+ findNewAddr(),
785+ exceptionType,
786+ useConcreteType = true ,
787+ mockInfoGenerator = mockInfoGenerator
788+ )
781789 val currentExceptionJimpleLocal = current.leftOp as JimpleLocal
782790
783791 queuedSymbolicStateUpdates + = localMemoryUpdate(currentExceptionJimpleLocal.variable to createdException)
@@ -1017,10 +1025,8 @@ class Traverser(
10171025 }
10181026 is StaticFieldRef -> {
10191027 val declaringClassType = fieldRef.field.declaringClass.type
1020- val fieldTypeId = fieldRef.field.type.classId
10211028 val generator = UtMockInfoGenerator { mockAddr ->
1022- val fieldId = FieldId (declaringClassType.id, fieldRef.field.name)
1023- UtFieldMockInfo (fieldTypeId, mockAddr, fieldId, ownerAddr = null )
1029+ UtStaticObjectMockInfo (declaringClassType.id, mockAddr)
10241030 }
10251031 findOrCreateStaticObject(declaringClassType, generator)
10261032 }
@@ -1375,7 +1381,7 @@ class Traverser(
13751381 addr : UtAddrExpression ,
13761382 type : RefType ,
13771383 useConcreteType : Boolean ,
1378- mockInfoGenerator : UtMockInfoGenerator ? = null
1384+ mockInfoGenerator : UtMockInfoGenerator ?
13791385 ): ObjectValue {
13801386 touchAddress(addr)
13811387 val nullEqualityConstraint = mkEq(addr, nullObjectAddr)
@@ -1422,10 +1428,10 @@ class Traverser(
14221428
14231429 // add typeConstraint for mocked object. It's a declared type of the object.
14241430 val typeConstraint = typeRegistry.typeConstraint(addr, mockedObject.typeStorage).all()
1425- val isMockConstraint = mkEq( typeRegistry.isMock (mockedObject.addr), UtTrue )
1431+ val isMockConstraint = typeRegistry.isMockConstraint (mockedObject.addr)
14261432
14271433 queuedSymbolicStateUpdates + = typeConstraint.asHardConstraint()
1428- queuedSymbolicStateUpdates + = mkOr( isMockConstraint, nullEqualityConstraint) .asHardConstraint()
1434+ queuedSymbolicStateUpdates + = isMockConstraint.asHardConstraint()
14291435
14301436 return mockedObject
14311437 }
@@ -1505,7 +1511,7 @@ class Traverser(
15051511 }
15061512
15071513 val concreteImplementation: Concrete ? = when (applicationContext.typeReplacementMode) {
1508- AnyImplementor -> findConcreteImplementation(addr, type, typeHardConstraint, nullEqualityConstraint )
1514+ AnyImplementor -> findConcreteImplementation(addr, type, typeHardConstraint)
15091515
15101516 // If our type is not abstract, both in `KnownImplementors` and `NoImplementors` mode,
15111517 // we should just still use concrete implementation that represents itself
@@ -1521,7 +1527,7 @@ class Traverser(
15211527 KnownImplementor ,
15221528 NoImplementors -> {
15231529 if (! type.isAbstractType) {
1524- findConcreteImplementation(addr, type, typeHardConstraint, nullEqualityConstraint )
1530+ findConcreteImplementation(addr, type, typeHardConstraint)
15251531 } else {
15261532 mockInfoGenerator?.let {
15271533 return createMockedObject(addr, type, it, nullEqualityConstraint)
@@ -1540,12 +1546,11 @@ class Traverser(
15401546 addr : UtAddrExpression ,
15411547 type : RefType ,
15421548 typeHardConstraint : HardConstraint ,
1543- nullEqualityConstraint : UtBoolExpression ,
15441549 ): Concrete ? {
15451550 val isMockConstraint = mkEq(typeRegistry.isMock(addr), UtFalse )
15461551
15471552 queuedSymbolicStateUpdates + = typeHardConstraint
1548- queuedSymbolicStateUpdates + = mkOr( isMockConstraint, nullEqualityConstraint) .asHardConstraint()
1553+ queuedSymbolicStateUpdates + = isMockConstraint.asHardConstraint()
15491554
15501555 // If we have this$0 with UtArrayList type, we have to create such instance.
15511556 // We should create an object with typeStorage of all possible real types and concrete implementation
@@ -1583,10 +1588,10 @@ class Traverser(
15831588
15841589 // add typeConstraint for mocked object. It's a declared type of the object.
15851590 val typeConstraint = typeRegistry.typeConstraint(addr, mockedObject.typeStorage).all()
1586- val isMockConstraint = mkEq( typeRegistry.isMock (mockedObject.addr), UtTrue )
1591+ val isMockConstraint = typeRegistry.isMockConstraint (mockedObject.addr)
15871592
15881593 queuedSymbolicStateUpdates + = typeConstraint.asHardConstraint()
1589- queuedSymbolicStateUpdates + = mkOr( isMockConstraint, nullEqualityConstraint) .asHardConstraint()
1594+ queuedSymbolicStateUpdates + = isMockConstraint.asHardConstraint()
15901595
15911596 return mockedObject
15921597 }
@@ -1606,7 +1611,8 @@ class Traverser(
16061611 // instead of it we create an unbounded symbolic variable
16071612 workaround(HACK ) {
16081613 offerState(environment.state.withLabel(StateLabel .CONCRETE ))
1609- createObject(addr, refType, useConcreteType = true )
1614+ // We don't need to mock a string constant creation
1615+ createObject(addr, refType, useConcreteType = true , mockInfoGenerator = null )
16101616 }
16111617 } else {
16121618 val typeStorage = TypeStorage .constructTypeStorageWithSingleType(refType)
@@ -2254,7 +2260,7 @@ class Traverser(
22542260 addr : UtAddrExpression ,
22552261 fieldType : Type ,
22562262 chunkId : ChunkId ,
2257- mockInfoGenerator : UtMockInfoGenerator ? = null
2263+ mockInfoGenerator : UtMockInfoGenerator ?
22582264 ): SymbolicValue {
22592265 val descriptor = MemoryChunkDescriptor (chunkId, objectType, fieldType)
22602266 val array = memory.findArray(descriptor)
@@ -2395,10 +2401,10 @@ class Traverser(
23952401 * Since createConst called only for objects from outside at the beginning of the analysis,
23962402 * we can set Le(addr, NULL_ADDR) for all RefValue objects.
23972403 */
2398- private fun Value.createConst (pName : String , mockInfoGenerator : UtMockInfoGenerator ? = null ): SymbolicValue =
2404+ private fun Value.createConst (pName : String , mockInfoGenerator : UtMockInfoGenerator ? ): SymbolicValue =
23992405 createConst(type, pName, mockInfoGenerator)
24002406
2401- fun createConst (type : Type , pName : String , mockInfoGenerator : UtMockInfoGenerator ? = null ): SymbolicValue =
2407+ fun createConst (type : Type , pName : String , mockInfoGenerator : UtMockInfoGenerator ? ): SymbolicValue =
24022408 when (type) {
24032409 is ByteType -> mkBVConst(pName, UtByteSort ).toByteValue()
24042410 is ShortType -> mkBVConst(pName, UtShortSort ).toShortValue()
@@ -3460,9 +3466,9 @@ class Traverser(
34603466
34613467 private fun unboundedVariable (name : String , method : SootMethod ): MethodResult {
34623468 val value = when (val returnType = method.returnType) {
3463- is RefType -> createObject(findNewAddr(), returnType, useConcreteType = true )
3469+ is RefType -> createObject(findNewAddr(), returnType, useConcreteType = true , mockInfoGenerator = null )
34643470 is ArrayType -> createArray(findNewAddr(), returnType, useConcreteType = true )
3465- else -> createConst(returnType, " $name${unboundedConstCounter++ } " )
3471+ else -> createConst(returnType, " $name${unboundedConstCounter++ } " , mockInfoGenerator = null )
34663472 }
34673473
34683474 return MethodResult (value)
0 commit comments