@@ -776,8 +776,16 @@ class Traverser(
776
776
777
777
private fun TraversalContext.skipVerticesForThrowableCreation (current : JAssignStmt ) {
778
778
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
+ )
781
789
val currentExceptionJimpleLocal = current.leftOp as JimpleLocal
782
790
783
791
queuedSymbolicStateUpdates + = localMemoryUpdate(currentExceptionJimpleLocal.variable to createdException)
@@ -1017,10 +1025,8 @@ class Traverser(
1017
1025
}
1018
1026
is StaticFieldRef -> {
1019
1027
val declaringClassType = fieldRef.field.declaringClass.type
1020
- val fieldTypeId = fieldRef.field.type.classId
1021
1028
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)
1024
1030
}
1025
1031
findOrCreateStaticObject(declaringClassType, generator)
1026
1032
}
@@ -1375,7 +1381,7 @@ class Traverser(
1375
1381
addr : UtAddrExpression ,
1376
1382
type : RefType ,
1377
1383
useConcreteType : Boolean ,
1378
- mockInfoGenerator : UtMockInfoGenerator ? = null
1384
+ mockInfoGenerator : UtMockInfoGenerator ?
1379
1385
): ObjectValue {
1380
1386
touchAddress(addr)
1381
1387
val nullEqualityConstraint = mkEq(addr, nullObjectAddr)
@@ -1422,10 +1428,10 @@ class Traverser(
1422
1428
1423
1429
// add typeConstraint for mocked object. It's a declared type of the object.
1424
1430
val typeConstraint = typeRegistry.typeConstraint(addr, mockedObject.typeStorage).all()
1425
- val isMockConstraint = mkEq( typeRegistry.isMock (mockedObject.addr), UtTrue )
1431
+ val isMockConstraint = typeRegistry.isMockConstraint (mockedObject.addr)
1426
1432
1427
1433
queuedSymbolicStateUpdates + = typeConstraint.asHardConstraint()
1428
- queuedSymbolicStateUpdates + = mkOr( isMockConstraint, nullEqualityConstraint) .asHardConstraint()
1434
+ queuedSymbolicStateUpdates + = isMockConstraint.asHardConstraint()
1429
1435
1430
1436
return mockedObject
1431
1437
}
@@ -1505,7 +1511,7 @@ class Traverser(
1505
1511
}
1506
1512
1507
1513
val concreteImplementation: Concrete ? = when (applicationContext.typeReplacementMode) {
1508
- AnyImplementor -> findConcreteImplementation(addr, type, typeHardConstraint, nullEqualityConstraint )
1514
+ AnyImplementor -> findConcreteImplementation(addr, type, typeHardConstraint)
1509
1515
1510
1516
// If our type is not abstract, both in `KnownImplementors` and `NoImplementors` mode,
1511
1517
// we should just still use concrete implementation that represents itself
@@ -1521,7 +1527,7 @@ class Traverser(
1521
1527
KnownImplementor ,
1522
1528
NoImplementors -> {
1523
1529
if (! type.isAbstractType) {
1524
- findConcreteImplementation(addr, type, typeHardConstraint, nullEqualityConstraint )
1530
+ findConcreteImplementation(addr, type, typeHardConstraint)
1525
1531
} else {
1526
1532
mockInfoGenerator?.let {
1527
1533
return createMockedObject(addr, type, it, nullEqualityConstraint)
@@ -1540,12 +1546,11 @@ class Traverser(
1540
1546
addr : UtAddrExpression ,
1541
1547
type : RefType ,
1542
1548
typeHardConstraint : HardConstraint ,
1543
- nullEqualityConstraint : UtBoolExpression ,
1544
1549
): Concrete ? {
1545
1550
val isMockConstraint = mkEq(typeRegistry.isMock(addr), UtFalse )
1546
1551
1547
1552
queuedSymbolicStateUpdates + = typeHardConstraint
1548
- queuedSymbolicStateUpdates + = mkOr( isMockConstraint, nullEqualityConstraint) .asHardConstraint()
1553
+ queuedSymbolicStateUpdates + = isMockConstraint.asHardConstraint()
1549
1554
1550
1555
// If we have this$0 with UtArrayList type, we have to create such instance.
1551
1556
// We should create an object with typeStorage of all possible real types and concrete implementation
@@ -1583,10 +1588,10 @@ class Traverser(
1583
1588
1584
1589
// add typeConstraint for mocked object. It's a declared type of the object.
1585
1590
val typeConstraint = typeRegistry.typeConstraint(addr, mockedObject.typeStorage).all()
1586
- val isMockConstraint = mkEq( typeRegistry.isMock (mockedObject.addr), UtTrue )
1591
+ val isMockConstraint = typeRegistry.isMockConstraint (mockedObject.addr)
1587
1592
1588
1593
queuedSymbolicStateUpdates + = typeConstraint.asHardConstraint()
1589
- queuedSymbolicStateUpdates + = mkOr( isMockConstraint, nullEqualityConstraint) .asHardConstraint()
1594
+ queuedSymbolicStateUpdates + = isMockConstraint.asHardConstraint()
1590
1595
1591
1596
return mockedObject
1592
1597
}
@@ -1606,7 +1611,8 @@ class Traverser(
1606
1611
// instead of it we create an unbounded symbolic variable
1607
1612
workaround(HACK ) {
1608
1613
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 )
1610
1616
}
1611
1617
} else {
1612
1618
val typeStorage = TypeStorage .constructTypeStorageWithSingleType(refType)
@@ -2254,7 +2260,7 @@ class Traverser(
2254
2260
addr : UtAddrExpression ,
2255
2261
fieldType : Type ,
2256
2262
chunkId : ChunkId ,
2257
- mockInfoGenerator : UtMockInfoGenerator ? = null
2263
+ mockInfoGenerator : UtMockInfoGenerator ?
2258
2264
): SymbolicValue {
2259
2265
val descriptor = MemoryChunkDescriptor (chunkId, objectType, fieldType)
2260
2266
val array = memory.findArray(descriptor)
@@ -2395,10 +2401,10 @@ class Traverser(
2395
2401
* Since createConst called only for objects from outside at the beginning of the analysis,
2396
2402
* we can set Le(addr, NULL_ADDR) for all RefValue objects.
2397
2403
*/
2398
- private fun Value.createConst (pName : String , mockInfoGenerator : UtMockInfoGenerator ? = null ): SymbolicValue =
2404
+ private fun Value.createConst (pName : String , mockInfoGenerator : UtMockInfoGenerator ? ): SymbolicValue =
2399
2405
createConst(type, pName, mockInfoGenerator)
2400
2406
2401
- fun createConst (type : Type , pName : String , mockInfoGenerator : UtMockInfoGenerator ? = null ): SymbolicValue =
2407
+ fun createConst (type : Type , pName : String , mockInfoGenerator : UtMockInfoGenerator ? ): SymbolicValue =
2402
2408
when (type) {
2403
2409
is ByteType -> mkBVConst(pName, UtByteSort ).toByteValue()
2404
2410
is ShortType -> mkBVConst(pName, UtShortSort ).toShortValue()
@@ -3460,9 +3466,9 @@ class Traverser(
3460
3466
3461
3467
private fun unboundedVariable (name : String , method : SootMethod ): MethodResult {
3462
3468
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 )
3464
3470
is ArrayType -> createArray(findNewAddr(), returnType, useConcreteType = true )
3465
- else -> createConst(returnType, " $name${unboundedConstCounter++ } " )
3471
+ else -> createConst(returnType, " $name${unboundedConstCounter++ } " , mockInfoGenerator = null )
3466
3472
}
3467
3473
3468
3474
return MethodResult (value)
0 commit comments