unittestbot / jacodb Goto Github PK
View Code? Open in Web Editor NEWfast and effective way to access and analyze java bytecode
License: Apache License 2.0
fast and effective way to access and analyze java bytecode
License: Apache License 2.0
Use some storage for saving information about processed byte-code and reuse it between launches.
Support querying data for few classes at the moment to fix N+1 query problem
Idea is to run jcdb in a separate process and be able to communicate with this instance from another process on a localhost
Add ability to implement additional features for JcClasspath. This brings clear ability to:
To think about: there is possibility that JcUnknownType
could be implemented and used by this feature
Analog of Shimple in Soot
Symptoms @volivan239:
Caused by: org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (incomplete input)
at org.sqlite.core.DB.newSQLException(DB.java:1135)
at org.sqlite.core.DB.newSQLException(DB.java:1146)
at org.sqlite.core.DB.throwex(DB.java:1106)
at org.sqlite.core.NativeDB.prepare_utf8(Native Method)
at org.sqlite.core.NativeDB.prepare(NativeDB.java:117)
at org.sqlite.core.DB.prepare(DB.java:264)
at org.sqlite.core.CorePreparedStatement.<init>(CorePreparedStatement.java:45)
at org.sqlite.jdbc3.JDBC3PreparedStatement.<init>(JDBC3PreparedStatement.java:30)
at org.sqlite.jdbc4.JDBC4PreparedStatement.<init>(JDBC4PreparedStatement.java:25)
at org.sqlite.jdbc4.JDBC4Connection.prepareStatement(JDBC4Connection.java:34)
at org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:155)
at org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:135)
at org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:140)
at org.utbot.jcdb.impl.storage.JooqKt.insertElements(Jooq.kt:33)
at org.utbot.jcdb.impl.storage.PersistentLocationRegistry$registerIfNeeded$1.invoke$lambda$4(PersistentLocationRegistry.kt:86)
at org.jooq.impl.DefaultDSLContext$4.run(DefaultDSLContext.java:683)
at org.jooq.impl.DefaultDSLContext$4.run(DefaultDSLContext.java:680)
at org.jooq.impl.DefaultDSLContext.connectionResult(DefaultDSLContext.java:662)
... 107 more
Kotlin tests are green if run separately.
Such as NotNull
which describes runtime environment for this code.
Using ASM library.
As an example one could take one of:
There are two cases which were not covered:
Calling JcApplicationGraphImpl.callers()
for some standard java methods leads to different not found
exceptions. For example,
@Test
fun `analyse something`() = runBlocking {
val graph = JcApplicationGraphImpl(cp, cp.usagesExt())
val callers = graph.callers(cp.findClass<java.util.StringTokenizer>().constructors[2])
println(callers.toList().size)
}
throws the following exception:
java.lang.IllegalStateException: com.sun.org.apache.xalan.internal.xsltc.compiler.Output#DUP not found
at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawFieldRef(JcGraphBuilder.kt:503)
at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawFieldRef(JcGraphBuilder.kt:176)
at org.jacodb.api.cfg.JcRawFieldRef.accept(JcRawInst.kt:832)
at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawAssignInst(JcGraphBuilder.kt:237)
Environment
IRTest:
10:21:40.334 [Test worker] WARN org.utbot.jacodb.impl.types.signature.MethodSignature - Can't parse signature '<X:Ljava/lang/Throwable;>(Ljava/lang/Throwable;Ljava/lang/Class<TX;>;)V^TX;' of field org.utbot.jacodb.impl.bytecode.JcMethodImpl@3e57d454
java.lang.ClassCastException: class org.utbot.jacodb.impl.types.signature.JvmTypeVariable cannot be cast to class org.utbot.jacodb.impl.types.signature.JvmClassRefType (org.utbot.jacodb.impl.types.signature.JvmTypeVariable and org.utbot.jacodb.impl.types.signature.JvmClassRefType are in unnamed module of loader 'app')
at org.utbot.jacodb.impl.types.signature.MethodSignature$ExceptionTypeRegistrant.register(MethodSignature.kt:81)
at org.utbot.jacodb.impl.types.signature.TypeExtractor.visitTypeVariable(TypeExtractor.kt:36)
at org.objectweb.asm.signature.SignatureReader.parseType(SignatureReader.java:178)
at org.objectweb.asm.signature.SignatureReader.accept(SignatureReader.java:117)
at org.utbot.jacodb.impl.types.signature.Signature$Companion.of(Signature.kt:68)
at org.utbot.jacodb.impl.types.signature.MethodSignature$Companion.withDeclarations(MethodSignature.kt:108)
at org.utbot.jacodb.impl.types.JcTypedMethodImpl$info$2.invoke(JcTypedMethodImpl.kt:65)
at org.utbot.jacodb.impl.types.JcTypedMethodImpl$info$2.invoke(JcTypedMethodImpl.kt:54)
at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
at org.utbot.jacodb.impl.types.JcTypedMethodImpl.getInfo(JcTypedMethodImpl.kt:54)
at org.utbot.jacodb.impl.types.JcTypedMethodImpl.getExceptions(JcTypedMethodImpl.kt:80)
at org.utbot.jacodb.impl.cfg.JcExceptionResolver.visitJcStaticCallExpr(GraphExt.kt:397)
at org.utbot.jacodb.impl.cfg.JcExceptionResolver.visitJcStaticCallExpr(GraphExt.kt:224)
at org.utbot.jacodb.api.cfg.JcStaticCallExpr.accept(JcInst.kt:693)
at org.utbot.jacodb.impl.cfg.JcExceptionResolver.visitJcCallInst(GraphExt.kt:241)
at org.utbot.jacodb.impl.cfg.JcExceptionResolver.visitJcCallInst(GraphExt.kt:224)
at org.utbot.jacodb.api.cfg.JcCallInst.accept(JcInst.kt:89)
at org.utbot.jacodb.impl.cfg.JcGraphImpl.<init>(JcGraphImpl.kt:74)
at org.utbot.jacodb.impl.cfg.JcGraphBuilder.build(JcGraphBuilder.kt:43)
at org.utbot.jacodb.impl.cfg.JcRawInstListImpl.graph(JcRawInstListImpl.kt:71)
at org.utbot.jacodb.api.JcMethod.flowGraph(Classes.kt:73)
at org.utbot.jacodb.impl.cfg.IRTest.testClass(IRTest.kt:366)
at org.utbot.jacodb.impl.cfg.IRTest.runAlongLib(IRTest.kt:348)
at org.utbot.jacodb.impl.cfg.IRTest.get ir of guava(IRTest.kt:333)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Currently we are looking for jar files inside installation. Add support for jmod files too
Ability to run tests under:
Split classpaths into hierarchy and has an default classpath instance for environment libraries (jvm libraries). That may reduce memory consumption because caches for environment librs may be shared. As an opposite side class caches may be stored on bytecode level.
For class found places:
Seems like JcTypedParameterImpl
stores type of parameters and not its name in JcTypedMethodParameter.name
. Consider the following test:
@Test
fun `my test`() {
class Example() {
fun f(notNullable: String, nullable: String?): Int {
return 0
}
}
val clazz = typeOf<Example>()
clazz as JcClassType
val actualParameters = clazz.declaredMethods.single { it.name == "f" }.parameters.map { it.name }
assertEquals(listOf("notNullable", "nullable"), actualParameters)
}
It fails with
Expected :[notNullable, nullable]
Actual :[java.lang.String, java.lang.String]
Sections
For this method
public static void main(String[] args) {
Benchmark.alloc(1);
A a = (A) Benchmark.taint(); //new A();
A b = new A(); // Added to avoid cfg optimizations
Benchmark.use(b);
b = a; // REVERSED assignment in IR
Benchmark.use(b);
Benchmark.use(a);
Benchmark.test("b",
"{allocId:1, mayAlias:[a,b], notMayAlias:[], mustAlias:[a,b], notMustAlias:[]}");
}
Describe:
When JetBrains will fix https://youtrack.jetbrains.com/issue/KTIJ-24248/False-positive-compile-error-for-Java-class-implementing-Kotlin-interface-with-JvmDefault-annotation issue in Kotlin plugin
Consider the following class:
class Example {
void derefAfterCheck() {
String myString = null;
if (myString == null)
{
IO.writeLine(myString.length());
}
}
}
And the corresponding test:
val method = cp.findClass<Example>().declaredMethods.single { it.name == "derefAfterCheck" }
method.flowGraph()
Call to JcMethod.flowGraph()
here fails with exception:
Could not find a method with correct signature java.lang.Object#length()I
java.lang.IllegalStateException: Could not find a method with correct signature java.lang.Object#length()I
at org.jacodb.impl.cfg.JcGraphBuilder.getMethod(JcGraphBuilder.kt:420)
at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawVirtualCallExpr(JcGraphBuilder.kt:457)
at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawVirtualCallExpr(JcGraphBuilder.kt:176)
at org.jacodb.api.cfg.JcRawVirtualCallExpr.accept(JcRawInst.kt:716)
at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawAssignInst(JcGraphBuilder.kt:237)
at org.jacodb.impl.cfg.JcGraphBuilder.visitJcRawAssignInst(JcGraphBuilder.kt:176)
at org.jacodb.api.cfg.JcRawAssignInst.accept(JcRawInst.kt:42)
at org.jacodb.impl.cfg.JcGraphBuilder.convertRawInst(JcGraphBuilder.kt:220)
at org.jacodb.impl.cfg.JcGraphBuilder.buildFlowGraph(JcGraphBuilder.kt:203)
at org.jacodb.impl.bytecode.JcMethodImpl.flowGraph(JcMethodImpl.kt:84)
...
The problem seems to be in incorrect assigning type Object
to localvar myString
due to null
-initialization
Such as:
Implement tree structure holding information about loaded classes from libraries/folders.
and implement reversed fields and methods index with extension which is not installed by default
Add api for indexing bytecode. Switch search of all subclasses to index api.
IRTest has 2 tests along pure java libraries: jackson and guava. Main target is to make them green.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.