Skip to content

Commit 1438c55

Browse files
Correct accessibily for package-private fields #1667 (#1685)
1 parent a4a3573 commit 1438c55

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ import org.utbot.framework.plugin.api.util.doubleStreamClassId
151151
import org.utbot.framework.plugin.api.util.doubleStreamToArrayMethodId
152152
import org.utbot.framework.plugin.api.util.intStreamClassId
153153
import org.utbot.framework.plugin.api.util.intStreamToArrayMethodId
154+
import org.utbot.framework.plugin.api.util.isPackagePrivate
154155
import org.utbot.framework.plugin.api.util.isSubtypeOf
155156
import org.utbot.framework.plugin.api.util.longStreamClassId
156157
import org.utbot.framework.plugin.api.util.longStreamToArrayMethodId
@@ -1112,7 +1113,11 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
11121113
private fun FieldId.getAccessExpression(variable: CgVariable): CgExpression =
11131114
// Can directly access field only if it is declared in variable class (or in its ancestors)
11141115
// and is accessible from current package
1115-
if (variable.type.hasField(this) && canBeReadFrom(context)) {
1116+
if (variable.type.hasField(this)
1117+
//TODO: think about moving variable type checks into [isAccessibleFrom] after contest
1118+
&& (!isPackagePrivate || variable.type.packageName == context.testClassPackageName)
1119+
&& canBeReadFrom(context)
1120+
) {
11161121
if (jField.isStatic) CgStaticFieldAccess(this) else CgFieldAccess(variable, this)
11171122
} else {
11181123
utilsClassId[getFieldValue](variable, this.declaringClass.name, this.name)

0 commit comments

Comments
 (0)