Skip to content

Codegen unable to properly instantiate public inner classes #761 #1009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ class ObjectModelProvider(
parameterIndex: Int,
classId: ClassId,
): Sequence<ModelConstructor> = sequence {
if (unwantedConstructorsClasses.contains(classId) ||
classId.isPrimitiveWrapper || classId.isEnum || classId.isAbstract
if (unwantedConstructorsClasses.contains(classId)
|| classId.isPrimitiveWrapper
|| classId.isEnum
|| classId.isAbstract
|| (classId.isInner && !classId.isStatic)
) return@sequence

val constructors = collectConstructors(classId) { javaConstructor ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.utbot.framework.plugin.api.samples;

public class WithInnerClass {
public class NonStatic {
public int x;
public NonStatic(int x) { this.x = x; }
}
int f(NonStatic b) {
return b.x * b.x;
}

public static class Static {
public int x;
public Static(int x) { this.x = x; }
}
int g(Static b) {
return b.x * b.x;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.utbot.framework.plugin.api.samples.FieldSetterClass
import org.utbot.framework.plugin.api.samples.OuterClassWithEnums
import org.utbot.framework.plugin.api.samples.PackagePrivateFieldAndClass
import org.utbot.framework.plugin.api.samples.SampleEnum
import org.utbot.framework.plugin.api.samples.WithInnerClass
import org.utbot.framework.plugin.api.util.executableId
import org.utbot.framework.plugin.api.util.primitiveByWrapper
import org.utbot.framework.plugin.api.util.primitiveWrappers
Expand Down Expand Up @@ -561,6 +562,29 @@ class ModelProviderTest {
}
}

@Test
fun `no models are created for inner non-static class`() {
withUtContext(UtContext(this::class.java.classLoader)) {
val result = collect(
ObjectModelProvider(TestIdentityPreservingIdGenerator),
parameters = listOf(WithInnerClass.NonStatic::class.id)
)
assertEquals(0, result.size)
}
}

@Test
fun `some models are created for inner static class`() {
withUtContext(UtContext(this::class.java.classLoader)) {
val result = collect(
ObjectModelProvider(TestIdentityPreservingIdGenerator),
parameters = listOf(WithInnerClass.Static::class.id)
)
assertEquals(1, result.size)
assertTrue(result[0]!!.isNotEmpty())
}
}

private enum class OneTwoThree {
ONE, TWO, THREE
}
Expand Down