File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
main/kotlin/org/utbot/framework/assemble
test/kotlin/org/utbot/examples/codegen
utbot-sample/src/main/java/org/utbot/examples/codegen Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import org.utbot.engine.ResolvedModels
6
6
import org.utbot.engine.isPrivate
7
7
import org.utbot.engine.isPublic
8
8
import org.utbot.framework.UtSettings
9
+ import org.utbot.framework.codegen.model.util.isAccessibleFrom
9
10
import org.utbot.framework.modifications.AnalysisMode.SettersAndDirectAccessors
10
11
import org.utbot.framework.modifications.ConstructorAnalyzer
11
12
import org.utbot.framework.modifications.ConstructorAssembleInfo
@@ -255,6 +256,11 @@ class AssembleModelGenerator(private val methodUnderTest: UtMethod<*>) {
255
256
if (fieldId.isFinal) {
256
257
throw AssembleException (" Final field $fieldId can't be set in an object of the class $classId " )
257
258
}
259
+ if (! fieldId.type.isAccessibleFrom(methodPackageName)) {
260
+ throw AssembleException (
261
+ " Field $fieldId can't be set in an object of the class $classId because its type is inaccessible"
262
+ )
263
+ }
258
264
// fill field value if it hasn't been filled by constructor, and it is not default
259
265
if (fieldId in constructorInfo.affectedFields ||
260
266
(fieldId !in constructorInfo.setFields && ! fieldModel.hasDefaultValue())
Original file line number Diff line number Diff line change @@ -97,6 +97,15 @@ internal class ClassWithStaticAndInnerClassesTest : UtValueTestCaseChecker(testC
97
97
)
98
98
}
99
99
100
+ @Test
101
+ fun testGetValueFromPublicFieldWithPrivateType () {
102
+ check(
103
+ ClassWithStaticAndInnerClasses ::getValueFromPublicFieldWithPrivateType,
104
+ eq(2 ),
105
+ coverage = DoNotCalculate
106
+ )
107
+ }
108
+
100
109
@Test
101
110
fun testPublicStaticClassWithPrivateField_DeepNestedStatic_g () {
102
111
checkAllCombinations(
Original file line number Diff line number Diff line change 3
3
public class ClassWithStaticAndInnerClasses {
4
4
public int z = 0 ;
5
5
6
+ // public field that exposes private type PrivateInnerClassWithPublicField
7
+ public PrivateInnerClassWithPublicField publicFieldWithPrivateType = new PrivateInnerClassWithPublicField (0 );
8
+
6
9
private static class PrivateStaticClassWithPublicField {
7
10
public int x ;
8
11
@@ -239,4 +242,8 @@ PackagePrivateFinalInnerClassWithPackagePrivateField usePackagePrivateFinalInner
239
242
240
243
return innerClass .createFromIncrement (x );
241
244
}
245
+
246
+ int getValueFromPublicFieldWithPrivateType () {
247
+ return publicFieldWithPrivateType .x ;
248
+ }
242
249
}
You can’t perform that action at this time.
0 commit comments