├── .github └── workflows │ ├── benchmarks.yml │ ├── build-and-test.yml │ ├── github-packages.yml │ ├── nightly-builds.yml │ ├── release.yml │ └── telegram-notifications.yml ├── .gitignore ├── LICENSE ├── NOTICE ├── README.md ├── add-licence.sh ├── add-license.bat ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ ├── Dependencies.kt │ └── Tests.kt ├── docs ├── badges │ ├── branches.svg │ ├── coverage-summary.json │ └── jacoco.svg ├── copyright │ └── COPYRIGHT_HEADER.txt └── svg │ ├── block-graph-IRExamples-concatTest-1.svg │ ├── block-graph-IRExamples-init-0.svg │ ├── block-graph-IRExamples-runBinarySearchIteratively-2.svg │ ├── block-graph-IRExamples-runBinarySearchIterativelyTryCatch-3.svg │ ├── block-graph-IRExamples-sortSequence-4.svg │ ├── block-graph-IRExamples-sortTimes-5.svg │ ├── block-graph-IRExamples-test-6.svg │ ├── block-graph-IRExamples-testField-7.svg │ ├── block-graph-IRExamples-testPrimitives-8.svg │ ├── graph-IRExamples-concatTest-1.svg │ ├── graph-IRExamples-init-0.svg │ ├── graph-IRExamples-runBinarySearchIteratively-2.svg │ ├── graph-IRExamples-runBinarySearchIterativelyTryCatch-3.svg │ ├── graph-IRExamples-sortSequence-4.svg │ ├── graph-IRExamples-sortTimes-5.svg │ ├── graph-IRExamples-test-6.svg │ ├── graph-IRExamples-testField-7.svg │ └── graph-IRExamples-testPrimitives-8.svg ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jacodb-analysis ├── README.md ├── build.gradle.kts └── src │ ├── main │ └── kotlin │ │ └── org │ │ └── jacodb │ │ └── analysis │ │ ├── config │ │ ├── Condition.kt │ │ ├── Position.kt │ │ └── TaintAction.kt │ │ ├── graph │ │ ├── ApplicationGraphFactory.kt │ │ ├── BackwardGraphs.kt │ │ ├── JcApplicationGraphImpl.kt │ │ ├── JcNoopInst.kt │ │ └── SimplifiedJcApplicationGraph.kt │ │ ├── ifds │ │ ├── AccessPath.kt │ │ ├── Accessors.kt │ │ ├── Analyzer.kt │ │ ├── Edge.kt │ │ ├── FlowFunctions.kt │ │ ├── IfdsResult.kt │ │ ├── Manager.kt │ │ ├── Maybe.kt │ │ ├── Reason.kt │ │ ├── Runner.kt │ │ ├── Summary.kt │ │ ├── TraceGraph.kt │ │ ├── UnitResolver.kt │ │ └── Vertex.kt │ │ ├── impl │ │ └── custom │ │ │ ├── AbstractFlowAnalysis.kt │ │ │ ├── BackwardFlowAnalysis.kt │ │ │ ├── FlowAnalysis.kt │ │ │ ├── FlowAnalysisImpl.kt │ │ │ ├── ForwardFlowAnalysis.kt │ │ │ ├── NullAssumptionAnalysis.kt │ │ │ └── ReachingDefinitionsAnalysis.kt │ │ ├── npe │ │ ├── NpeAnalyzers.kt │ │ ├── NpeFlowFunctions.kt │ │ ├── NpeManager.kt │ │ └── Utils.kt │ │ ├── sarif │ │ ├── Sarif.kt │ │ ├── SourceFileResolver.kt │ │ └── Vulnerability.kt │ │ ├── taint │ │ ├── Sarif.kt │ │ ├── TaintAnalyzers.kt │ │ ├── TaintBidiRunner.kt │ │ ├── TaintEvents.kt │ │ ├── TaintFacts.kt │ │ ├── TaintFlowFunctions.kt │ │ ├── TaintManager.kt │ │ ├── TaintSummaries.kt │ │ └── Types.kt │ │ ├── unused │ │ ├── Sarif.kt │ │ ├── UnusedVariableAnalyzer.kt │ │ ├── UnusedVariableEvents.kt │ │ ├── UnusedVariableFacts.kt │ │ ├── UnusedVariableFlowFunctions.kt │ │ ├── UnusedVariableManager.kt │ │ ├── UnusedVariableSummaries.kt │ │ └── Utils.kt │ │ └── util │ │ └── Utils.kt │ └── test │ ├── java │ └── org │ │ └── jacodb │ │ └── analysis │ │ └── impl │ │ └── JavaAnalysisApiTest.java │ ├── kotlin │ └── org │ │ └── jacodb │ │ └── analysis │ │ └── impl │ │ ├── BaseAnalysisTest.kt │ │ ├── ConditionEvaluatorTest.kt │ │ ├── IfdsNpeTest.kt │ │ ├── IfdsSqlTest.kt │ │ ├── IfdsUnusedTest.kt │ │ ├── JodaDateTimeAnalysisTest.kt │ │ ├── NullabilityAssumptionAnalysisTest.kt │ │ └── TaintFlowFunctionsTest.kt │ └── resources │ ├── additional.json │ ├── config_small.json │ ├── config_test.json │ ├── pointerbench.jar │ └── simplelogger.properties ├── jacodb-api ├── README.md ├── build.gradle.kts └── src │ └── main │ └── kotlin │ └── org │ └── jacodb │ └── api │ ├── Api.kt │ ├── Classes.kt │ ├── Exceptions.kt │ ├── Hook.kt │ ├── Index.kt │ ├── JcClasspath.kt │ ├── JcLookup.kt │ ├── PredefinedPrimitive.kt │ ├── Resolution.kt │ ├── Substitution.kt │ ├── Symbols.kt │ ├── Types.kt │ ├── analysis │ ├── ApplicationGraph.kt │ ├── JcApplicationGraph.kt │ ├── JcPointsToAnalysis.kt │ └── PrimitivePointsAnalysis.kt │ ├── cfg │ ├── FullExprSetCollector.kt │ ├── JcBlockGraph.kt │ ├── JcBytecodeGraph.kt │ ├── JcGraph.kt │ ├── JcGraphs.kt │ ├── JcInst.kt │ ├── JcInstList.kt │ ├── JcInstVisitor.kt │ ├── JcRawInst.kt │ └── JcRawInstVisitor.kt │ └── ext │ ├── HierarchyExtension.kt │ ├── JcClasses.kt │ ├── JcClasspaths.kt │ ├── JcCommons.kt │ ├── JcFields.kt │ ├── JcMethods.kt │ ├── JcTypes.kt │ ├── Nullables.kt │ └── cfg │ └── JcInstructions.kt ├── jacodb-approximations ├── README.md ├── build.gradle.kts └── src │ ├── main │ └── kotlin │ │ └── org │ │ └── jacodb │ │ └── approximation │ │ ├── Approximations.kt │ │ ├── InstSubstitutorForApproximations.kt │ │ ├── TransformerIntoVirtual.kt │ │ ├── Util.kt │ │ ├── VirtualInstances.kt │ │ ├── VirtualInstancesBuilders.kt │ │ └── annotation │ │ └── ApproximationAnnotations.kt │ └── test │ ├── java │ └── org │ │ └── jacodb │ │ └── approximations │ │ └── approx │ │ └── IntegerApprox.java │ └── kotlin │ └── org │ └── jacodb │ └── approximations │ ├── ApproximationsTest.kt │ ├── approx │ └── KotlinClassApprox.kt │ └── target │ └── KotlinClass.kt ├── jacodb-benchmarks ├── build.gradle.kts └── src │ └── test │ └── kotlin │ └── org │ └── jacodb │ └── testing │ └── performance │ ├── JcInstructionsBenchmark.kt │ ├── JcdbAwaitBackgroundBenchmarks.kt │ ├── JcdbBenchmarks.kt │ ├── JcdbLifeCycleBenchmarks.kt │ ├── RestoreJcdbBenchmark.kt │ ├── SootBenchmarks.kt │ ├── SootupBenchmarks.kt │ └── TakeMemoryDump.kt ├── jacodb-cli ├── build.gradle.kts └── src │ ├── main │ └── kotlin │ │ └── org │ │ └── jacodb │ │ └── cli │ │ └── main.kt │ └── test │ ├── kotlin │ └── org │ │ └── jacodb │ │ └── cli │ │ └── CliTest.kt │ └── resources │ └── config.json ├── jacodb-core ├── README.md ├── build.gradle.kts └── src │ ├── main │ ├── jooq │ │ └── org │ │ │ └── jacodb │ │ │ └── impl │ │ │ └── storage │ │ │ └── jooq │ │ │ ├── DefaultCatalog.kt │ │ │ ├── DefaultSchema.kt │ │ │ ├── indexes │ │ │ └── Indexes.kt │ │ │ ├── keys │ │ │ └── Keys.kt │ │ │ └── tables │ │ │ ├── Annotations.kt │ │ │ ├── Annotationvalues.kt │ │ │ ├── Applicationmetadata.kt │ │ │ ├── Builders.kt │ │ │ ├── Bytecodelocations.kt │ │ │ ├── Calls.kt │ │ │ ├── Classes.kt │ │ │ ├── Classhierarchies.kt │ │ │ ├── Classinnerclasses.kt │ │ │ ├── Fields.kt │ │ │ ├── Methodparameters.kt │ │ │ ├── Methods.kt │ │ │ ├── Outerclasses.kt │ │ │ ├── Refactorings.kt │ │ │ ├── Symbols.kt │ │ │ ├── records │ │ │ ├── AnnotationsRecord.kt │ │ │ ├── AnnotationvaluesRecord.kt │ │ │ ├── ApplicationmetadataRecord.kt │ │ │ ├── BuildersRecord.kt │ │ │ ├── BytecodelocationsRecord.kt │ │ │ ├── CallsRecord.kt │ │ │ ├── ClassesRecord.kt │ │ │ ├── ClasshierarchiesRecord.kt │ │ │ ├── ClassinnerclassesRecord.kt │ │ │ ├── FieldsRecord.kt │ │ │ ├── MethodparametersRecord.kt │ │ │ ├── MethodsRecord.kt │ │ │ ├── OuterclassesRecord.kt │ │ │ ├── RefactoringsRecord.kt │ │ │ └── SymbolsRecord.kt │ │ │ └── references │ │ │ └── Tables.kt │ ├── kotlin │ │ └── org │ │ │ └── jacodb │ │ │ └── impl │ │ │ ├── Async.kt │ │ │ ├── FeaturesRegistry.kt │ │ │ ├── JcClasspathImpl.kt │ │ │ ├── JcDatabaseImpl.kt │ │ │ ├── JcSettings.kt │ │ │ ├── LocationsRegistry.kt │ │ │ ├── analysis │ │ │ └── impl │ │ │ │ └── StringConcatSimplifierTransformer.kt │ │ │ ├── bytecode │ │ │ ├── Conversions.kt │ │ │ ├── JcAbstractLookup.kt │ │ │ ├── JcAnnotationImpl.kt │ │ │ ├── JcClassLookupImpl.kt │ │ │ ├── JcClassOrInterfaceImpl.kt │ │ │ ├── JcDatabaseClassWritter.kt │ │ │ ├── JcDeclarationImpl.kt │ │ │ ├── JcFieldImpl.kt │ │ │ ├── JcMethodImpl.kt │ │ │ ├── JcParameterImpl.kt │ │ │ ├── KMetadata.kt │ │ │ └── util.kt │ │ │ ├── cfg │ │ │ ├── GraphExt.kt │ │ │ ├── JcBlockGraphImpl.kt │ │ │ ├── JcGraphImpl.kt │ │ │ ├── JcInstListBuilder.kt │ │ │ ├── JcInstListImpl.kt │ │ │ ├── MethodNodeBuilder.kt │ │ │ ├── RawInstListBuilder.kt │ │ │ ├── Simplifier.kt │ │ │ ├── TypedMethodRefImpl.kt │ │ │ ├── ValueExt.kt │ │ │ ├── graphs │ │ │ │ ├── DominatorsTree.kt │ │ │ │ └── GraphDominators.kt │ │ │ └── util │ │ │ │ ├── ExprMapper.kt │ │ │ │ ├── InstructionFilter.kt │ │ │ │ ├── Loops.kt │ │ │ │ ├── printer.kt │ │ │ │ └── types.kt │ │ │ ├── features │ │ │ ├── BuilderExtension.kt │ │ │ ├── Builders.kt │ │ │ ├── Diagnostics.kt │ │ │ ├── HierarchyExtension.kt │ │ │ ├── InMemoryHierarchy.kt │ │ │ ├── JcFeaturesChain.kt │ │ │ ├── UsageRequest.kt │ │ │ ├── Usages.kt │ │ │ ├── UsagesExtension.kt │ │ │ └── classpaths │ │ │ │ ├── ClasspathCache.kt │ │ │ │ ├── Events.kt │ │ │ │ ├── JcUnknownClass.kt │ │ │ │ ├── JcUnknownType.kt │ │ │ │ ├── KotlinMetadata.kt │ │ │ │ ├── MethodInstructionsFeature.kt │ │ │ │ ├── StringConcatSimplifier.kt │ │ │ │ ├── VirtualClassContent.kt │ │ │ │ ├── VirtualClasses.kt │ │ │ │ └── virtual │ │ │ │ ├── JcVirtualClass.kt │ │ │ │ ├── JcVirtualField.kt │ │ │ │ ├── JcVirtualMethod.kt │ │ │ │ └── VirtualClassesBuilder.kt │ │ │ ├── fs │ │ │ ├── AbstractByteCodeLocation.kt │ │ │ ├── BuildFolderLocation.kt │ │ │ ├── ByteCodeConverter.kt │ │ │ ├── ByteCodeLoaderImpl.kt │ │ │ ├── ByteCodeLocations.kt │ │ │ ├── ClassSource.kt │ │ │ ├── JarLocationImpl.kt │ │ │ ├── Jars.kt │ │ │ ├── JavaRuntime.kt │ │ │ └── JavaVersionImpl.kt │ │ │ ├── jacodb.kt │ │ │ ├── storage │ │ │ ├── AbstractJcDatabasePersistenceImpl.kt │ │ │ ├── Caches.kt │ │ │ ├── DataStorageException.kt │ │ │ ├── Enums.kt │ │ │ ├── JcRefactoring.kt │ │ │ ├── Jooq.kt │ │ │ ├── PersistenceService.kt │ │ │ ├── PersistentLocationRegistry.kt │ │ │ └── SQLitePersistenceImpl.kt │ │ │ ├── types │ │ │ ├── JcArrayTypeImpl.kt │ │ │ ├── JcClassTypeImpl.kt │ │ │ ├── JcClassTypeLookup.kt │ │ │ ├── JcGenericTypes.kt │ │ │ ├── JcTypeBindings.kt │ │ │ ├── JcTypedFieldImpl.kt │ │ │ ├── JcTypedMethodImpl.kt │ │ │ ├── JcTypedMethodParameterImpl.kt │ │ │ ├── Objects.kt │ │ │ ├── TypeParameters.kt │ │ │ ├── signature │ │ │ │ ├── FieldSignature.kt │ │ │ │ ├── JvmTypeAnnotationUpdateVisitor.kt │ │ │ │ ├── JvmTypeCopyWithExt.kt │ │ │ │ ├── JvmTypeKMetadataUpdateVisitor.kt │ │ │ │ ├── JvmTypeParameterDeclaration.kt │ │ │ │ ├── JvmTypes.kt │ │ │ │ ├── MethodSignature.kt │ │ │ │ ├── RecordSignature.kt │ │ │ │ ├── Resolutions.kt │ │ │ │ ├── Signature.kt │ │ │ │ ├── TypeExtractor.kt │ │ │ │ ├── TypeRegistrant.kt │ │ │ │ └── TypeSignature.kt │ │ │ └── substition │ │ │ │ ├── JcSubstitutorImpl.kt │ │ │ │ ├── JcSubstitutors.kt │ │ │ │ └── RecursiveJvmTypeVisitor.kt │ │ │ └── vfs │ │ │ ├── ClassTreeListener.kt │ │ │ ├── ClassVfsItem.kt │ │ │ ├── ClasspathVfs.kt │ │ │ ├── GlobalClassesVfs.kt │ │ │ ├── PackageVfsItem.kt │ │ │ ├── PersistentByteCodeLocation.kt │ │ │ └── Vfs.kt │ └── resources │ │ ├── jacodb.properties │ │ └── sqlite │ │ ├── add-indexes.sql │ │ ├── create-schema.sql │ │ ├── drop-schema.sql │ │ ├── empty.db │ │ └── usages │ │ ├── add-indexes.sql │ │ ├── create-schema.sql │ │ └── drop-schema.sql │ ├── test │ ├── java │ │ └── org │ │ │ └── jacodb │ │ │ └── testing │ │ │ ├── JavaApi.java │ │ │ └── JavaApiTest.java │ ├── kotlin │ │ └── org │ │ │ └── jacodb │ │ │ └── testing │ │ │ ├── AnnotationsTest.kt │ │ │ ├── ApiExtTest.kt │ │ │ ├── Bar.kt │ │ │ ├── ClassesTest.kt │ │ │ ├── DatabaseLifecycleTest.kt │ │ │ ├── DirectUsagesTest.kt │ │ │ ├── HierarchyStabilityTest.kt │ │ │ ├── JarFacadeTest.kt │ │ │ ├── JavaVersionTest.kt │ │ │ ├── ParameterNamesTest.kt │ │ │ ├── SignatureTest.kt │ │ │ ├── SubclassesTest.kt │ │ │ ├── UnknownClassesTest.kt │ │ │ ├── cfg │ │ │ ├── BaseInstructionsTest.kt │ │ │ ├── IRSvgGenerator.kt │ │ │ ├── IRTest.kt │ │ │ ├── IincTest.kt │ │ │ ├── InstructionsTest.kt │ │ │ ├── InvokeDynamicTest.kt │ │ │ ├── KotlinInstructionsTest.kt │ │ │ └── LoopsTest.kt │ │ │ ├── features │ │ │ ├── BaseSearchUsagesTest.kt │ │ │ ├── BuildersTest.kt │ │ │ └── InMemoryHierarchyTest.kt │ │ │ ├── persistence │ │ │ ├── IncompleteDataTest.kt │ │ │ └── RestoredDBTest.kt │ │ │ ├── tree │ │ │ ├── DummyCodeLocation.kt │ │ │ └── GlobalClassVfsTest.kt │ │ │ └── types │ │ │ ├── AssignTypesTest.kt │ │ │ ├── BaseTypesTest.kt │ │ │ ├── IgnoreSubstitutionProblemsTest.kt │ │ │ ├── InnerTypesTest.kt │ │ │ ├── LinkedGenericsTest.kt │ │ │ ├── MultiParametersTest.kt │ │ │ ├── OverridesTest.kt │ │ │ ├── RecursiveTypesTest.kt │ │ │ ├── TypeAnnotationsTest.kt │ │ │ ├── TypesTest.kt │ │ │ ├── WildcardTypesTest.kt │ │ │ └── nullability │ │ │ ├── JavaNullabilityTest.kt │ │ │ ├── KotlinJavaInteropNullabilityTest.kt │ │ │ ├── KotlinNullabilityTest.kt │ │ │ └── TypeNullabilityTree.kt │ └── resources │ │ ├── samples │ │ ├── GenericsApi.class │ │ ├── GenericsApiConsumer.class │ │ ├── PhantomClassSubclass.class │ │ ├── PhantomCodeConsumer.class │ │ ├── PhantomDeclaration.class │ │ ├── PhantomDeclarationConsumer.class │ │ ├── TestLDC.class │ │ └── VirtualInstructions.class │ │ └── src │ │ ├── GenericsApi.java │ │ ├── PhantomClass.java │ │ ├── PhantomClassSubclass.java │ │ ├── PhantomCodeConsumer.java │ │ ├── PhantomDeclaration.java │ │ ├── PhantomDeclarationConsumer.java │ │ ├── PhantomInterface.java │ │ ├── PhantomInterfaceConsumer.java │ │ └── PhantomInterfaceImpl.java │ └── testFixtures │ ├── java │ └── org │ │ └── jacodb │ │ └── testing │ │ ├── Bar.java │ │ ├── Common.java │ │ ├── analysis │ │ ├── NpeExamples.java │ │ └── SqlInjectionExamples.java │ │ ├── builders │ │ ├── Hierarchy.java │ │ ├── Interfaces.java │ │ └── Simple.java │ │ ├── cfg │ │ ├── ArgAssignmentExample.java │ │ ├── BinarySearchTree.java │ │ ├── Close.java │ │ ├── Conditionals.java │ │ ├── IRExamples.java │ │ ├── Incrementation.java │ │ ├── InvokeDynamicExamples.java │ │ ├── JavaArrays.java │ │ ├── JavaTasks.java │ │ ├── Lambdas.java │ │ ├── MultiplyTests.java │ │ ├── NullAssumptionAnalysisExample.java │ │ ├── SimpleAlias1.java │ │ └── StaticInterfaceMethodCall.java │ │ ├── hierarchies │ │ ├── Creature.java │ │ ├── Inheritance.java │ │ └── Overrides.java │ │ ├── primitives │ │ └── Primitives.java │ │ ├── structure │ │ ├── EnumExamples.java │ │ ├── FieldsAndMethods.java │ │ └── HiddenFieldSuperClass.java │ │ ├── types │ │ ├── AAA.java │ │ ├── Comparables.java │ │ ├── Generics.java │ │ ├── InnerClasses.java │ │ ├── MultipleParametrization.java │ │ ├── NullAnnotationExamples.java │ │ ├── PrimitiveAndArrays.java │ │ └── WildcardBounds.java │ │ └── usages │ │ ├── Generics.java │ │ ├── HelloWorldAnonymousClasses.java │ │ ├── WithInner.java │ │ ├── direct │ │ └── DirectA.java │ │ ├── fields │ │ ├── FakeFieldA.java │ │ ├── FieldA.java │ │ └── FieldB.java │ │ └── methods │ │ ├── MethodA.java │ │ ├── MethodB.java │ │ └── MethodC.java │ └── kotlin │ └── org │ └── jacodb │ └── testing │ ├── BaseTest.kt │ ├── Enums.kt │ ├── Foo.kt │ ├── Hierarchy.kt │ ├── KotlinNullabilityExamples.kt │ ├── LibrariesMixin.kt │ ├── cfg │ ├── Arrays.kt │ ├── DefaultArgs.kt │ ├── DifferentReceivers.kt │ ├── DoubleComparison.kt │ ├── Equals.kt │ ├── Iinc.kt │ ├── InvokeMethodWithException.kt │ ├── Overloading.kt │ ├── Ranges.kt │ ├── Sequence.kt │ ├── SimpleTest.kt │ ├── TryCatchFinally.kt │ ├── Varargs.kt │ └── WhenExpr.kt │ └── tests │ └── DatabaseEnvTest.kt ├── jacodb-examples ├── build.gradle.kts └── src │ └── main │ ├── java │ └── org │ │ └── jacodb │ │ └── examples │ │ └── JavaReadMeExamples.java │ └── kotlin │ └── org │ └── jacodb │ └── examples │ ├── KotlinReadMeExamples.kt │ └── analysis │ ├── PerformanceMetrics.kt │ └── SootPerformanceMetrics.kt ├── jacodb-taint-configuration ├── README.md ├── build.gradle.kts └── src │ ├── main │ └── kotlin │ │ └── org │ │ └── jacodb │ │ └── taint │ │ └── configuration │ │ ├── ConfigurationTrie.kt │ │ ├── Position.kt │ │ ├── SerializedTaintConfigurationItem.kt │ │ ├── TaintAction.kt │ │ ├── TaintCondition.kt │ │ ├── TaintConfigurationFeature.kt │ │ ├── TaintConfigurationItem.kt │ │ ├── TaintMark.kt │ │ └── Util.kt │ └── test │ ├── kotlin │ └── org │ │ └── jacodb │ │ └── taint │ │ └── configuration │ │ ├── ConfigurationTest.kt │ │ └── UtilTest.kt │ └── resources │ └── testJsonConfig.json ├── pre-commit └── settings.gradle.kts /.github/workflows/benchmarks.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | # This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time 6 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 7 | 8 | name: Run benchmarks 9 | 10 | on: 11 | schedule: 12 | - cron: '30 23 * * 1,2,3,4,5' 13 | 14 | permissions: 15 | contents: read 16 | 17 | jobs: 18 | jdk11: 19 | 20 | runs-on: ubuntu-latest 21 | 22 | steps: 23 | - uses: actions/checkout@v3 24 | - name: Set up JDK 11 25 | uses: actions/setup-java@v3 26 | with: 27 | java-version: '11' 28 | distribution: 'temurin' 29 | - uses: gradle/gradle-build-action@v2 30 | with: 31 | gradle-version: 7.6.1 32 | - name: Build and run tests 33 | run: | 34 | gradle benchmark --no-daemon --info 35 | 36 | jdk8: 37 | 38 | runs-on: ubuntu-latest 39 | 40 | steps: 41 | - uses: actions/checkout@v3 42 | - name: Set up JDK 8 43 | uses: actions/setup-java@v3 44 | with: 45 | java-version: '8' 46 | distribution: 'zulu' 47 | java-package: jdk+fx 48 | - uses: gradle/gradle-build-action@v2 49 | with: 50 | gradle-version: 7.6.1 51 | - name: Build and run tests 52 | run: | 53 | gradle benchmark --no-daemon --info 54 | -------------------------------------------------------------------------------- /.github/workflows/github-packages.yml: -------------------------------------------------------------------------------- 1 | name: Publish to GitHub packages 2 | 3 | on: 4 | push: 5 | branches: 6 | - develop 7 | 8 | jobs: 9 | publish: 10 | runs-on: ubuntu-latest 11 | permissions: 12 | contents: read 13 | packages: write 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Set up JDK 11 17 | uses: actions/setup-java@v3 18 | with: 19 | java-version: '11' 20 | distribution: 'temurin' 21 | - name: Publish package 22 | uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 23 | with: 24 | gradle-version: 7.6.1 25 | arguments: | 26 | publish 27 | -Pactor=${{ github.actor }} 28 | -Ptoken=${{ secrets.GITHUB_TOKEN }} 29 | -PrepoUrl=https://maven.pkg.github.com/UnitTestBot/jacodb 30 | -------------------------------------------------------------------------------- /.github/workflows/nightly-builds.yml: -------------------------------------------------------------------------------- 1 | name: Nightly builds for Maven Central 2 | 3 | on: 4 | schedule: 5 | - cron: '30 23 * * 1,2,3,4,5' 6 | 7 | jobs: 8 | publish: 9 | runs-on: ubuntu-latest 10 | permissions: 11 | contents: read 12 | packages: write 13 | steps: 14 | - uses: actions/checkout@v3 15 | with: 16 | ref: develop 17 | - name: Set up JDK 11 18 | uses: actions/setup-java@v3 19 | with: 20 | java-version: '11' 21 | distribution: 'temurin' 22 | - name: Publish package 23 | uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 24 | with: 25 | gradle-version: 7.6.1 26 | arguments: | 27 | publish 28 | -Pactor=${{ secrets.MAVEN_CENTRAL_LOGIN }} 29 | -Ptoken=${{ secrets.MAVEN_CENTRAL_TOKEN }} 30 | -PrepoUrl=https://s01.oss.sonatype.org/content/repositories/snapshots/ 31 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | run-name: Releasing ${{inputs.semVer}} 3 | 4 | on: 5 | workflow_dispatch: 6 | inputs: 7 | semVer: 8 | required: true 9 | type: string 10 | description: "Version number" 11 | 12 | jobs: 13 | publish: 14 | if: ${{ github.actor == 'lehvolk' || github.actor == 'denis-fokin' || github.actor == 'bissquit' || github.actor == 'Vassiliy-Kudryashov' }} 15 | runs-on: ubuntu-latest 16 | permissions: 17 | contents: write 18 | packages: write 19 | steps: 20 | - uses: actions/checkout@v3 21 | - name: Set up JDK 11 22 | uses: actions/setup-java@v3 23 | with: 24 | java-version: '11' 25 | distribution: 'temurin' 26 | - name: Publish package 27 | uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 28 | with: 29 | gradle-version: 7.6.1 30 | arguments: | 31 | publish 32 | -PincludeDokka=true 33 | -PsemVer=${{inputs.semVer}} 34 | -Pactor=${{ secrets.MAVEN_CENTRAL_LOGIN }} 35 | -Ptoken=${{ secrets.MAVEN_CENTRAL_TOKEN }} 36 | -PgpgKey="${{ secrets.OSSRH_GPG_SECRET_KEY }}" 37 | -PgpgPassphrase=${{ secrets.OSSRH_GPG_SECRET_PASSPHRASE }} 38 | -PrepoUrl=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ 39 | - name: Upload release artifacts 40 | uses: softprops/action-gh-release@v1 41 | with: 42 | draft: true 43 | files: | 44 | jacodb-api/build/libs/jacodb-api-${{inputs.semVer}}.jar 45 | jacodb-approximations/build/libs/jacodb-approximations-${{inputs.semVer}}.jar 46 | jacodb-taint-configuration/build/libs/jacodb-taint-configuration-${{inputs.semVer}}.jar 47 | jacodb-analysis/build/libs/jacodb-analysis-${{inputs.semVer}}.jar 48 | jacodb-core/build/libs/jacodb-core-${{inputs.semVer}}.jar 49 | jacodb-cli/build/libs/jacodb-cli-${{inputs.semVer}}.jar 50 | jacodb-examples/build/libs/jacodb-examples-${{inputs.semVer}}.jar 51 | -------------------------------------------------------------------------------- /.github/workflows/telegram-notifications.yml: -------------------------------------------------------------------------------- 1 | name: Telegram Pull Request Notifier 2 | 3 | on: 4 | pull_request: 5 | types: [opened, review_requested] 6 | 7 | jobs: 8 | notification: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Pull Request Telegram 13 | uses: F2had/pr-telegram-action@v1.0.0 14 | with: 15 | bot_token: '${{ secrets.TELEGRAM_TOKEN }}' 16 | chat_id: '${{ secrets.TELEGRAM_CHAT_ID }}' -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .gradle/ 3 | build/ 4 | idea-community 5 | *.db 6 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | UnitTestBot 2 | Copyright 2022 UnitTestBot contributors (utbot.org) -------------------------------------------------------------------------------- /add-licence.sh: -------------------------------------------------------------------------------- 1 | ./gradlew licenseFormat -------------------------------------------------------------------------------- /add-license.bat: -------------------------------------------------------------------------------- 1 | ./gradlew licenseFormat -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | -------------------------------------------------------------------------------- /buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/buildSrc/settings.gradle.kts -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/Tests.kt: -------------------------------------------------------------------------------- 1 | import org.gradle.api.tasks.TaskProvider 2 | import org.gradle.api.tasks.testing.Test 3 | 4 | object Tests { 5 | val lifecycleTag = "lifecycle" 6 | 7 | } 8 | 9 | fun Test.setup(jacocoTestReport: TaskProvider<*>) { 10 | testLogging { 11 | events("passed", "skipped", "failed") 12 | } 13 | finalizedBy(jacocoTestReport) // report is always generated after tests run 14 | jvmArgs = listOf("-Xmx2g", "-XX:+HeapDumpOnOutOfMemoryError", "-XX:HeapDumpPath=heapdump.hprof") 15 | } 16 | -------------------------------------------------------------------------------- /docs/badges/branches.svg: -------------------------------------------------------------------------------- 1 | branches68.8% -------------------------------------------------------------------------------- /docs/badges/coverage-summary.json: -------------------------------------------------------------------------------- 1 | {"branches": 68.83633809412315, "coverage": 70.64358620296952} -------------------------------------------------------------------------------- /docs/badges/jacoco.svg: -------------------------------------------------------------------------------- 1 | coverage70.6% -------------------------------------------------------------------------------- /docs/copyright/COPYRIGHT_HEADER.txt: -------------------------------------------------------------------------------- 1 | Copyright 2022 UnitTestBot contributors (utbot.org) 2 |

3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 |

7 | http://www.apache.org/licenses/LICENSE-2.0 8 |

9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /docs/svg/block-graph-IRExamples-concatTest-1.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | jcGraph 11 | 12 | 13 | 0 14 | 15 | %0 = new java.lang.StringBuilder 16 | %0.<init>() 17 | %1 = %0.append(arg$0) 18 | %2 = %1.append(arg$1) 19 | %3 = %2.toString() 20 | return %3 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /docs/svg/block-graph-IRExamples-init-0.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | jcGraph 11 | 12 | 13 | 0 14 | 15 | this.<init>() 16 | return 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/svg/block-graph-IRExamples-testField-7.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | jcGraph 11 | 12 | 13 | 0 14 | 15 | this.x = arg$0 16 | return 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/svg/graph-IRExamples-init-0.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | jcGraph 11 | 12 | 13 | 0 14 | 15 | this.<init>() 16 | 17 | 18 | 19 | 1 20 | 21 | return 22 | 23 | 24 | 25 | 0->1 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/svg/graph-IRExamples-testField-7.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | jcGraph 11 | 12 | 13 | 0 14 | 15 | this.x = arg$0 16 | 17 | 18 | 19 | 1 20 | 21 | return 22 | 23 | 24 | 25 | 0->1 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | 3 | intellij_community_url=https://download-cdn.jetbrains.com/idea/ideaIC-2022.2.3.win.zip 4 | #database_location=d:\\work\\jacodb\\jcdb-http.db 5 | 6 | org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /jacodb-analysis/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("plugin.serialization") 3 | `java-test-fixtures` 4 | } 5 | 6 | dependencies { 7 | api(project(":jacodb-core")) 8 | api(project(":jacodb-api")) 9 | api(project(":jacodb-taint-configuration")) 10 | 11 | implementation(Libs.kotlin_logging) 12 | implementation(Libs.slf4j_simple) 13 | implementation(Libs.kotlinx_coroutines_core) 14 | implementation(Libs.kotlinx_serialization_json) 15 | api(Libs.sarif4k) 16 | 17 | testImplementation(testFixtures(project(":jacodb-core"))) 18 | testImplementation(project(":jacodb-api")) 19 | testImplementation(kotlin("test")) 20 | testImplementation(Libs.mockk) 21 | 22 | // Additional deps for analysis: 23 | testImplementation(files("src/test/resources/pointerbench.jar")) 24 | testImplementation(Libs.joda_time) 25 | testImplementation(Libs.juliet_support) 26 | for (cweNum in listOf(89, 476, 563, 690)) { 27 | testImplementation(Libs.juliet_cwe(cweNum)) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/graph/JcNoopInst.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.graph 18 | 19 | import org.jacodb.api.cfg.JcExpr 20 | import org.jacodb.api.cfg.JcInst 21 | import org.jacodb.api.cfg.JcInstLocation 22 | import org.jacodb.api.cfg.JcInstVisitor 23 | 24 | data class JcNoopInst(override val location: JcInstLocation) : JcInst { 25 | override val operands: List 26 | get() = emptyList() 27 | 28 | override fun accept(visitor: JcInstVisitor): T { 29 | return visitor.visitExternalJcInst(this) 30 | } 31 | 32 | override fun toString(): String = "noop" 33 | } 34 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/ifds/Accessors.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.ifds 18 | 19 | import org.jacodb.api.JcField 20 | 21 | sealed interface Accessor { 22 | fun toSuffix(): String 23 | } 24 | 25 | data class FieldAccessor( 26 | val field: JcField, 27 | ) : Accessor { 28 | override fun toSuffix(): String = ".${field.name}" 29 | override fun toString(): String = field.name 30 | } 31 | 32 | object ElementAccessor : Accessor { 33 | override fun toSuffix(): String = "[*]" 34 | override fun toString(): String = "*" 35 | } 36 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/ifds/Analyzer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.ifds 18 | 19 | interface Analyzer { 20 | val flowFunctions: FlowFunctions 21 | 22 | fun handleNewEdge( 23 | edge: Edge, 24 | ): List 25 | 26 | fun handleCrossUnitCall( 27 | caller: Vertex, 28 | callee: Vertex, 29 | ): List 30 | } 31 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/ifds/Edge.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.ifds 18 | 19 | import org.jacodb.api.JcMethod 20 | 21 | data class Edge( 22 | val from: Vertex, 23 | val to: Vertex, 24 | ) { 25 | init { 26 | require(from.method == to.method) 27 | } 28 | 29 | val method: JcMethod 30 | get() = from.method 31 | } 32 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/ifds/Manager.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.ifds 18 | 19 | import kotlinx.coroutines.CoroutineScope 20 | import org.jacodb.api.JcMethod 21 | 22 | interface Manager { 23 | fun handleEvent(event: Event) 24 | 25 | fun handleControlEvent(event: ControlEvent) 26 | 27 | fun subscribeOnSummaryEdges( 28 | method: JcMethod, 29 | scope: CoroutineScope, 30 | handler: (Edge) -> Unit, 31 | ) 32 | } 33 | 34 | sealed interface ControlEvent 35 | 36 | data class QueueEmptinessChanged( 37 | val runner: Runner<*>, 38 | val isEmpty: Boolean, 39 | ) : ControlEvent 40 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/ifds/Reason.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.ifds 18 | 19 | sealed interface Reason { 20 | object Initial : Reason 21 | 22 | object External : Reason 23 | 24 | data class CrossUnitCall( 25 | val caller: Vertex, 26 | ) : Reason 27 | 28 | data class Sequent( 29 | val edge: Edge, 30 | ) : Reason 31 | 32 | data class CallToStart( 33 | val edge: Edge, 34 | ) : Reason 35 | 36 | data class ThroughSummary( 37 | val edge: Edge, 38 | val summaryEdge: Edge, 39 | ) : Reason 40 | } 41 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/ifds/Vertex.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.ifds 18 | 19 | import org.jacodb.api.JcMethod 20 | import org.jacodb.api.cfg.JcInst 21 | 22 | data class Vertex( 23 | val statement: JcInst, 24 | val fact: Fact, 25 | ) { 26 | val method: JcMethod 27 | get() = statement.location.method 28 | } 29 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/impl/custom/AbstractFlowAnalysis.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.impl.custom 18 | 19 | import org.jacodb.api.cfg.JcBytecodeGraph 20 | 21 | abstract class AbstractFlowAnalysis(override val graph: JcBytecodeGraph) : FlowAnalysis { 22 | 23 | override fun newEntryFlow(): T = newFlow() 24 | 25 | protected open fun merge(successor: NODE, income1: T, income2: T, outcome: T) { 26 | merge(income1, income2, outcome) 27 | } 28 | 29 | open fun ins(s: NODE): T? { 30 | return ins[s] 31 | } 32 | 33 | protected fun mergeInto(successor: NODE, input: T, incoming: T) { 34 | val tmp = newFlow() 35 | merge(successor, input, incoming, tmp) 36 | copy(tmp, input) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/impl/custom/BackwardFlowAnalysis.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.impl.custom 18 | 19 | import org.jacodb.api.cfg.JcBytecodeGraph 20 | 21 | abstract class BackwardFlowAnalysis(graph: JcBytecodeGraph) : FlowAnalysisImpl(graph) { 22 | 23 | override val isForward: Boolean = false 24 | 25 | override fun run() { 26 | runAnalysis(FlowAnalysisDirection.BACKWARD, outs, ins) 27 | } 28 | } -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/impl/custom/FlowAnalysis.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.impl.custom 18 | 19 | import org.jacodb.api.cfg.JcBytecodeGraph 20 | 21 | interface FlowAnalysis { 22 | 23 | val ins: MutableMap 24 | val outs: MutableMap 25 | 26 | val graph: JcBytecodeGraph 27 | 28 | val isForward: Boolean 29 | 30 | fun newFlow(): T 31 | 32 | fun newEntryFlow(): T 33 | 34 | fun merge(in1: T, in2: T, out: T) 35 | 36 | fun copy(source: T?, dest: T) 37 | 38 | fun run() 39 | } -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/impl/custom/ForwardFlowAnalysis.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.impl.custom 18 | 19 | import org.jacodb.api.cfg.JcBytecodeGraph 20 | 21 | 22 | abstract class ForwardFlowAnalysis(graph: JcBytecodeGraph) : FlowAnalysisImpl(graph) { 23 | 24 | override val isForward = true 25 | 26 | override fun run() { 27 | runAnalysis(FlowAnalysisDirection.FORWARD, ins, outs) 28 | } 29 | } -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/npe/Utils.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.npe 18 | 19 | import org.jacodb.analysis.ifds.AccessPath 20 | import org.jacodb.analysis.ifds.toPathOrNull 21 | import org.jacodb.analysis.util.startsWith 22 | import org.jacodb.api.cfg.JcExpr 23 | import org.jacodb.api.cfg.JcInst 24 | import org.jacodb.api.cfg.JcInstanceCallExpr 25 | import org.jacodb.api.cfg.JcLengthExpr 26 | import org.jacodb.api.cfg.values 27 | 28 | fun AccessPath?.isDereferencedAt(expr: JcExpr): Boolean { 29 | if (this == null) { 30 | return false 31 | } 32 | 33 | if (expr is JcInstanceCallExpr) { 34 | val instancePath = expr.instance.toPathOrNull() 35 | if (instancePath.startsWith(this)) { 36 | return true 37 | } 38 | } 39 | 40 | if (expr is JcLengthExpr) { 41 | val arrayPath = expr.array.toPathOrNull() 42 | if (arrayPath.startsWith(this)) { 43 | return true 44 | } 45 | } 46 | 47 | return expr.values 48 | .mapNotNull { it.toPathOrNull() } 49 | .any { 50 | (it - this)?.isNotEmpty() == true 51 | } 52 | } 53 | 54 | fun AccessPath?.isDereferencedAt(inst: JcInst): Boolean { 55 | if (this == null) return false 56 | return inst.operands.any { isDereferencedAt(it) } 57 | } 58 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/sarif/SourceFileResolver.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.sarif 18 | 19 | import org.jacodb.api.cfg.JcInst 20 | 21 | fun interface SourceFileResolver { 22 | fun resolve(inst: JcInst): String? 23 | } 24 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/sarif/Vulnerability.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.sarif 18 | 19 | import io.github.detekt.sarif4k.Level 20 | import org.jacodb.analysis.ifds.TraceGraph 21 | 22 | data class VulnerabilityInstance( 23 | val traceGraph: TraceGraph, 24 | val description: VulnerabilityDescription, 25 | ) 26 | 27 | data class VulnerabilityDescription( 28 | val ruleId: String?, 29 | val message: String?, 30 | val level: Level = Level.Warning, 31 | ) 32 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/taint/Sarif.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.taint 18 | 19 | import org.jacodb.analysis.ifds.TraceGraph 20 | import org.jacodb.analysis.sarif.VulnerabilityDescription 21 | import org.jacodb.analysis.sarif.VulnerabilityInstance 22 | 23 | fun TaintVulnerability.toSarif( 24 | graph: TraceGraph, 25 | ): VulnerabilityInstance { 26 | return VulnerabilityInstance( 27 | graph, 28 | VulnerabilityDescription( 29 | ruleId = null, 30 | message = rule?.ruleNote 31 | ) 32 | ) 33 | } 34 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/taint/TaintEvents.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.taint 18 | 19 | import org.jacodb.analysis.ifds.Reason 20 | 21 | sealed interface TaintEvent 22 | 23 | data class NewSummaryEdge( 24 | val edge: TaintEdge, 25 | ) : TaintEvent 26 | 27 | data class NewVulnerability( 28 | val vulnerability: TaintVulnerability, 29 | ) : TaintEvent 30 | 31 | data class EdgeForOtherRunner( 32 | val edge: TaintEdge, 33 | val reason: Reason 34 | ) : TaintEvent { 35 | init { 36 | // TODO: remove this check 37 | check(edge.from == edge.to) { "Edge for another runner must be a loop" } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/taint/TaintFacts.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.taint 18 | 19 | import org.jacodb.analysis.ifds.AccessPath 20 | import org.jacodb.taint.configuration.TaintMark 21 | 22 | sealed interface TaintDomainFact 23 | 24 | object TaintZeroFact : TaintDomainFact { 25 | override fun toString(): String = "Zero" 26 | } 27 | 28 | data class Tainted( 29 | val variable: AccessPath, 30 | val mark: TaintMark, 31 | ) : TaintDomainFact 32 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/taint/TaintSummaries.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.taint 18 | 19 | import org.jacodb.analysis.ifds.SummaryEdge 20 | import org.jacodb.analysis.ifds.Vulnerability 21 | import org.jacodb.taint.configuration.TaintMethodSink 22 | 23 | data class TaintSummaryEdge( 24 | override val edge: TaintEdge, 25 | ) : SummaryEdge 26 | 27 | data class TaintVulnerability( 28 | override val message: String, 29 | override val sink: TaintVertex, 30 | val rule: TaintMethodSink? = null, 31 | ) : Vulnerability 32 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/taint/Types.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.taint 18 | 19 | import org.jacodb.analysis.ifds.Edge 20 | import org.jacodb.analysis.ifds.Runner 21 | import org.jacodb.analysis.ifds.Vertex 22 | 23 | typealias TaintVertex = Vertex 24 | typealias TaintEdge = Edge 25 | typealias TaintRunner = Runner 26 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/unused/Sarif.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.unused 18 | 19 | import org.jacodb.analysis.ifds.TraceGraph 20 | import org.jacodb.analysis.sarif.VulnerabilityDescription 21 | import org.jacodb.analysis.sarif.VulnerabilityInstance 22 | 23 | fun UnusedVariableVulnerability.toSarif(): VulnerabilityInstance { 24 | return VulnerabilityInstance( 25 | TraceGraph(sink, mutableSetOf(sink), mutableMapOf(), emptyMap()), 26 | VulnerabilityDescription(ruleId = null, message = message) 27 | ) 28 | } 29 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/unused/UnusedVariableAnalyzer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.unused 18 | 19 | import org.jacodb.analysis.ifds.Analyzer 20 | import org.jacodb.analysis.ifds.Edge 21 | import org.jacodb.analysis.ifds.Vertex 22 | import org.jacodb.api.analysis.JcApplicationGraph 23 | import org.jacodb.api.cfg.JcInst 24 | 25 | class UnusedVariableAnalyzer( 26 | private val graph: JcApplicationGraph, 27 | ) : Analyzer { 28 | 29 | override val flowFunctions: UnusedVariableFlowFunctions by lazy { 30 | UnusedVariableFlowFunctions(graph) 31 | } 32 | 33 | private fun isExitPoint(statement: JcInst): Boolean { 34 | return statement in graph.exitPoints(statement.location.method) 35 | } 36 | 37 | override fun handleNewEdge(edge: Edge): List = buildList { 38 | if (isExitPoint(edge.to.statement)) { 39 | add(NewSummaryEdge(edge)) 40 | } 41 | } 42 | 43 | override fun handleCrossUnitCall(caller: Vertex, callee: Vertex): List { 44 | return emptyList() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/unused/UnusedVariableEvents.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.unused 18 | 19 | import org.jacodb.analysis.ifds.Edge 20 | 21 | sealed interface Event 22 | 23 | data class NewSummaryEdge( 24 | val edge: Edge, 25 | ) : Event 26 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/unused/UnusedVariableFacts.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.unused 18 | 19 | import org.jacodb.analysis.ifds.AccessPath 20 | import org.jacodb.api.cfg.JcInst 21 | 22 | sealed interface UnusedVariableDomainFact 23 | 24 | object UnusedVariableZeroFact : UnusedVariableDomainFact { 25 | override fun toString(): String = "Zero" 26 | } 27 | 28 | data class UnusedVariable( 29 | val variable: AccessPath, 30 | val initStatement: JcInst, 31 | ) : UnusedVariableDomainFact 32 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/unused/UnusedVariableSummaries.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.analysis.unused 18 | 19 | import org.jacodb.analysis.ifds.Edge 20 | import org.jacodb.analysis.ifds.SummaryEdge 21 | import org.jacodb.analysis.ifds.Vertex 22 | import org.jacodb.analysis.ifds.Vulnerability 23 | 24 | data class UnusedVariableSummaryEdge( 25 | override val edge: Edge, 26 | ) : SummaryEdge 27 | 28 | data class UnusedVariableVulnerability( 29 | override val message: String, 30 | override val sink: Vertex, 31 | ) : Vulnerability 32 | -------------------------------------------------------------------------------- /jacodb-analysis/src/test/resources/pointerbench.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/jacodb-analysis/src/test/resources/pointerbench.jar -------------------------------------------------------------------------------- /jacodb-analysis/src/test/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | # SLF4J's SimpleLogger configuration file 2 | # Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err. 3 | 4 | # Default logging detail level for all instances of SimpleLogger. 5 | # Must be one of ("trace", "debug", "info", "warn", or "error"). 6 | # If not specified, defaults to "info". 7 | org.slf4j.simpleLogger.defaultLogLevel=info 8 | 9 | # Logging detail level for a SimpleLogger instance named "xxxxx". 10 | # Must be one of ("trace", "debug", "info", "warn", or "error"). 11 | # If not specified, the default logging detail level is used. 12 | org.slf4j.simpleLogger.log.org.jacodb.analysis.ifds=debug 13 | 14 | # Set to true if you want the current date and time to be included in output messages. 15 | # Default is false, and will output the number of milliseconds elapsed since startup. 16 | org.slf4j.simpleLogger.showDateTime=true 17 | 18 | # The date and time format to be used in the output messages. 19 | # The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat. 20 | # If the format is not specified or is invalid, the default format is used. 21 | # The default format is yyyy-MM-dd HH:mm:ss:SSS Z. 22 | org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss 23 | 24 | # Set to true if you want to output the current thread name. 25 | # Defaults to true. 26 | org.slf4j.simpleLogger.showThreadName=false 27 | 28 | # Set to true if you want the Logger instance name to be included in output messages. 29 | # Defaults to true. 30 | org.slf4j.simpleLogger.showLogName=true 31 | 32 | # Set to true if you want the last component of the name to be included in output messages. 33 | # Defaults to false. 34 | org.slf4j.simpleLogger.showShortLogName=true 35 | -------------------------------------------------------------------------------- /jacodb-api/build.gradle.kts: -------------------------------------------------------------------------------- 1 | dependencies { 2 | api(Libs.asm) 3 | api(Libs.asm_tree) 4 | api(Libs.asm_commons) 5 | api(Libs.asm_util) 6 | 7 | api(Libs.kotlinx_collections_immutable) 8 | api(Libs.kotlinx_coroutines_core) 9 | api(Libs.kotlinx_coroutines_jdk8) 10 | 11 | api(Libs.jooq) 12 | } 13 | -------------------------------------------------------------------------------- /jacodb-api/src/main/kotlin/org/jacodb/api/Exceptions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.api 18 | 19 | /** 20 | * This exception should be thrown when classpath is incomplete 21 | */ 22 | class NoClassInClasspathException(val className: String) : Exception("Class $className not found in classpath") 23 | 24 | /** 25 | * This exception should be thrown when classpath is incomplete 26 | */ 27 | class TypeNotFoundException(val typeName: String) : Exception("Type $typeName not found in classpath") 28 | 29 | class MethodNotFoundException(msg: String) : Exception(msg) 30 | 31 | fun String.throwClassNotFound(): Nothing { 32 | throw NoClassInClasspathException(this) 33 | } 34 | 35 | inline fun throwClassNotFound(): Nothing { 36 | T::class.java.name.throwClassNotFound() 37 | } -------------------------------------------------------------------------------- /jacodb-api/src/main/kotlin/org/jacodb/api/Hook.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.api 18 | 19 | interface Hook { 20 | 21 | suspend fun afterStart() 22 | 23 | fun afterStop() {} 24 | } -------------------------------------------------------------------------------- /jacodb-api/src/main/kotlin/org/jacodb/api/Resolution.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.api 18 | 19 | 20 | interface Resolution 21 | interface MethodResolution : Resolution 22 | interface RecordComponentResolution : Resolution 23 | interface FieldResolution : Resolution 24 | interface TypeResolution : Resolution 25 | 26 | object Malformed : TypeResolution, FieldResolution, MethodResolution, RecordComponentResolution 27 | object Pure : TypeResolution, FieldResolution, MethodResolution, RecordComponentResolution 28 | -------------------------------------------------------------------------------- /jacodb-api/src/main/kotlin/org/jacodb/api/analysis/ApplicationGraph.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.api.analysis 18 | 19 | /** 20 | * Provides both CFG and call graph (i.e., the supergraph in terms of RHS95 paper). 21 | */ 22 | interface ApplicationGraph { 23 | fun predecessors(node: Statement): Sequence 24 | fun successors(node: Statement): Sequence 25 | 26 | fun callees(node: Statement): Sequence 27 | fun callers(method: Method): Sequence 28 | 29 | fun entryPoints(method: Method): Sequence 30 | fun exitPoints(method: Method): Sequence 31 | 32 | fun methodOf(node: Statement): Method 33 | } 34 | -------------------------------------------------------------------------------- /jacodb-api/src/main/kotlin/org/jacodb/api/analysis/JcApplicationGraph.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.api.analysis 18 | 19 | import org.jacodb.api.JcClasspath 20 | import org.jacodb.api.JcMethod 21 | import org.jacodb.api.cfg.JcInst 22 | 23 | /** 24 | * Interface for [ApplicationGraph] built with jacodb. 25 | */ 26 | interface JcApplicationGraph : ApplicationGraph { 27 | val classpath: JcClasspath 28 | } -------------------------------------------------------------------------------- /jacodb-api/src/main/kotlin/org/jacodb/api/cfg/JcBytecodeGraph.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.api.cfg 18 | 19 | interface Graph : Iterable { 20 | 21 | fun successors(node: NODE): Set 22 | fun predecessors(node: NODE): Set 23 | } 24 | 25 | interface JcBytecodeGraph : Graph { 26 | 27 | val entries: List 28 | val exits: List 29 | 30 | fun throwers(node: NODE): Set 31 | fun catchers(node: NODE): Set 32 | 33 | } -------------------------------------------------------------------------------- /jacodb-api/src/main/kotlin/org/jacodb/api/cfg/JcInstList.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.api.cfg 18 | 19 | interface JcInstList : Iterable { 20 | val instructions: List 21 | val size: Int 22 | val indices: IntRange 23 | val lastIndex: Int 24 | 25 | operator fun get(index: Int): INST 26 | fun getOrNull(index: Int): INST? 27 | 28 | fun toMutableList(): JcMutableInstList 29 | } 30 | 31 | interface JcMutableInstList : JcInstList { 32 | fun insertBefore(inst: INST, vararg newInstructions: INST) 33 | fun insertBefore(inst: INST, newInstructions: Collection) 34 | fun insertAfter(inst: INST, vararg newInstructions: INST) 35 | fun insertAfter(inst: INST, newInstructions: Collection) 36 | fun remove(inst: INST): Boolean 37 | fun removeAll(inst: Collection): Boolean 38 | } -------------------------------------------------------------------------------- /jacodb-api/src/main/kotlin/org/jacodb/api/ext/HierarchyExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.api.ext 18 | 19 | import org.jacodb.api.JcClassOrInterface 20 | import org.jacodb.api.JcMethod 21 | 22 | /** 23 | * hierarchy extension for classpath 24 | */ 25 | interface HierarchyExtension { 26 | 27 | /** 28 | * find all subclasses or implementations if name points to interface. If [allHierarchy] is true then search 29 | * will be done recursively 30 | * 31 | * @return list with unique ClassId 32 | */ 33 | fun findSubClasses(name: String, allHierarchy: Boolean, includeOwn: Boolean = false): Sequence 34 | 35 | /** 36 | * find all subclasses or implementations if name points to interface. If [allHierarchy] is true then search 37 | * will be done recursively 38 | * 39 | * @return list with unique ClassId 40 | */ 41 | fun findSubClasses(jcClass: JcClassOrInterface, allHierarchy: Boolean, includeOwn: Boolean = false): Sequence 42 | 43 | /** 44 | * find overrides of current method 45 | * @return list with unique methods overriding current 46 | */ 47 | fun findOverrides(jcMethod: JcMethod, includeAbstract: Boolean = true): Sequence 48 | 49 | } -------------------------------------------------------------------------------- /jacodb-api/src/main/kotlin/org/jacodb/api/ext/JcFields.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("JcFields") 18 | 19 | package org.jacodb.api.ext 20 | 21 | import org.jacodb.api.JcField 22 | import org.objectweb.asm.Opcodes 23 | 24 | /** 25 | * is item has `volatile` modifier 26 | */ 27 | val JcField.isVolatile: Boolean 28 | get() { 29 | return access and Opcodes.ACC_VOLATILE != 0 30 | } 31 | 32 | /** 33 | * is field has `transient` modifier 34 | */ 35 | val JcField.isTransient: Boolean 36 | get() { 37 | return access and Opcodes.ACC_TRANSIENT != 0 38 | } 39 | 40 | 41 | val JcField.isEnum: Boolean 42 | get() { 43 | return access and Opcodes.ACC_ENUM != 0 44 | } 45 | -------------------------------------------------------------------------------- /jacodb-approximations/README.md: -------------------------------------------------------------------------------- 1 | # Module jacodb-approximation 2 | 3 | [Approximations] is used for overriding and extending existed classes by methods with their bodies. 4 | 5 | Use [Approximate] annotation on class and point it to target class. 6 | 7 | ```java 8 | @Approximate(java.lang.Integer.class) 9 | public class IntegerApprox { 10 | private final int value; 11 | 12 | public IntegerApprox(int value) { 13 | this.value = value; 14 | } 15 | 16 | public static IntegerApprox valueOf(int value) { 17 | return new IntegerApprox(value); 18 | } 19 | 20 | public int getValue() { 21 | return value; 22 | } 23 | } 24 | ``` 25 | 26 | Let's assume code: 27 | 28 | ```kotlin 29 | val db = jacodb { 30 | installFeature(Approximations) 31 | } 32 | val cp = db.classpath(emptyList(), listOf(Approximations)) 33 | val clazz = cp.findClass("java.lang.Integer") 34 | ``` 35 | 36 | `clazz` object will represent mix between `java.lang.Integer` and `IntegerApprox`: 37 | - static `valueOf` method will be from `IntegerApprox` and will reduce all complexity of java runtime 38 | - `getValue` and `` method will be also from `IntegerApprox` 39 | - all other methods will be from `java.lang.Integer` 40 | 41 | 42 | 43 | 44 | [Approximations]: https://jacodb.org/docs/jacodb-approximations/org.jacodb.approximation/-approximations/index.html 45 | [Approximate]: https://jacodb.org/docs/jacodb-approximations/org.jacodb.approximation.annotation/-approximate/index.html -------------------------------------------------------------------------------- /jacodb-approximations/build.gradle.kts: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation(project(":jacodb-api")) 3 | implementation(project(":jacodb-core")) 4 | implementation(testFixtures(project(":jacodb-core"))) 5 | 6 | testImplementation(Libs.kotlin_logging) 7 | testRuntimeOnly(Libs.guava) 8 | } 9 | -------------------------------------------------------------------------------- /jacodb-approximations/src/main/kotlin/org/jacodb/approximation/Util.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.approximation 18 | 19 | import org.jacodb.api.TypeName 20 | import org.jacodb.approximation.Approximations.findOriginalByApproximationOrNull 21 | import org.jacodb.impl.types.TypeNameImpl 22 | 23 | fun String.toApproximationName() = ApproximationClassName(this) 24 | fun String.toOriginalName() = OriginalClassName(this) 25 | 26 | fun TypeName.eliminateApproximation(): TypeName { 27 | val originalClassName = findOriginalByApproximationOrNull(typeName.toApproximationName()) ?: return this 28 | return TypeNameImpl(originalClassName) 29 | } -------------------------------------------------------------------------------- /jacodb-approximations/src/main/kotlin/org/jacodb/approximation/annotation/ApproximationAnnotations.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.approximation.annotation 18 | 19 | import kotlin.reflect.KClass 20 | 21 | @Suppress("unused") 22 | @Target(AnnotationTarget.CLASS) 23 | annotation class Approximate(val value: KClass<*>) 24 | -------------------------------------------------------------------------------- /jacodb-approximations/src/test/java/org/jacodb/approximations/approx/IntegerApprox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.approximations.approx; 18 | 19 | import org.jacodb.approximation.annotation.Approximate; 20 | 21 | 22 | @Approximate(java.lang.Integer.class) 23 | public class IntegerApprox { 24 | private final int value; 25 | 26 | public IntegerApprox(int value) { 27 | this.value = value; 28 | } 29 | 30 | public static IntegerApprox valueOf(int value) { 31 | return new IntegerApprox(value); 32 | } 33 | 34 | public int getValue() { 35 | return value; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jacodb-approximations/src/test/kotlin/org/jacodb/approximations/target/KotlinClass.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.approximations.target 18 | 19 | class KotlinClass { 20 | private val fieldToReplace: Int = 42 21 | private val sameApproximationTarget: KotlinClass? = null 22 | private val anotherApproximationTarget: Int? = null 23 | private val fieldWithoutApproximation: ClassForField = ClassForField() 24 | 25 | fun replaceBehaviour(value: Int): Int { 26 | if (value == fieldToReplace) { 27 | return -1; 28 | } 29 | 30 | return -2; 31 | } 32 | 33 | fun methodWithoutApproximation(): Int = 42 34 | 35 | fun useSameApproximationTarget(kotlinClass: KotlinClass): Int { 36 | if (kotlinClass == sameApproximationTarget) { 37 | return 1 38 | } 39 | 40 | return 0 41 | } 42 | 43 | fun useAnotherApproximationTarget(value: Int): Int { 44 | if (value == anotherApproximationTarget) { 45 | return 1 46 | } 47 | 48 | return 0 49 | } 50 | 51 | fun useFieldWithoutApproximation(classForField: ClassForField): Int { 52 | if (classForField == fieldWithoutApproximation) { 53 | return 1 54 | } 55 | 56 | return 0 57 | } 58 | } 59 | 60 | class ClassForField -------------------------------------------------------------------------------- /jacodb-benchmarks/src/test/kotlin/org/jacodb/testing/performance/JcdbLifeCycleBenchmarks.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.performance 18 | 19 | import kotlinx.coroutines.runBlocking 20 | import org.jacodb.api.JcDatabase 21 | import org.jacodb.impl.features.Usages 22 | import org.jacodb.impl.jacodb 23 | import org.jacodb.testing.allJars 24 | import org.openjdk.jmh.annotations.* 25 | import java.util.concurrent.TimeUnit 26 | 27 | @State(Scope.Benchmark) 28 | @Fork(0) 29 | @Warmup(iterations = 2) 30 | @BenchmarkMode(Mode.AverageTime) 31 | @OutputTimeUnit(TimeUnit.MILLISECONDS) 32 | @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.MILLISECONDS) 33 | class JcdbLifeCycleBenchmarks { 34 | 35 | private lateinit var db: JcDatabase 36 | 37 | @Setup(Level.Iteration) 38 | fun setup() { 39 | db = runBlocking { 40 | jacodb { 41 | installFeatures(Usages) 42 | useProcessJavaRuntime() 43 | } 44 | } 45 | } 46 | 47 | @Benchmark 48 | fun loadAdditionalJars() { 49 | val jars = allJars 50 | runBlocking { 51 | db.load(jars) 52 | } 53 | } 54 | 55 | @Benchmark 56 | fun awaitIndexing() { 57 | runBlocking { 58 | db.awaitBackgroundJobs() 59 | } 60 | } 61 | 62 | @TearDown(Level.Iteration) 63 | fun tearDown() { 64 | db.close() 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /jacodb-cli/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("plugin.serialization") 3 | } 4 | 5 | dependencies { 6 | api(project(":jacodb-core")) 7 | api(project(":jacodb-analysis")) 8 | api(project(":jacodb-api")) 9 | 10 | implementation(Libs.kotlin_logging) 11 | implementation(Libs.kotlinx_cli) 12 | implementation(Libs.kotlinx_serialization_json) 13 | 14 | testImplementation(testFixtures(project(":jacodb-core"))) 15 | } 16 | -------------------------------------------------------------------------------- /jacodb-cli/src/test/kotlin/org/jacodb/cli/CliTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.cli 18 | 19 | import org.jacodb.testing.analysis.NpeExamples 20 | import org.junit.jupiter.api.Test 21 | 22 | class CliTest { 23 | @Test 24 | fun `test basic analysis cli api`() { 25 | val args = listOf( 26 | "-a", CliTest::class.java.getResource("/config.json")?.file ?: error("Can't find file with config"), 27 | "-s", NpeExamples::class.java.name 28 | ) 29 | AnalysisMain().run(args) 30 | } 31 | } -------------------------------------------------------------------------------- /jacodb-cli/src/test/resources/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "analyses": { 3 | "NPE": {}, 4 | "Unused": { 5 | "UnitResolver": "class" 6 | }, 7 | "SQL": {} 8 | } 9 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/jooq/org/jacodb/impl/storage/jooq/DefaultCatalog.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * This file is generated by jOOQ. 19 | */ 20 | package org.jacodb.impl.storage.jooq 21 | 22 | 23 | import org.jooq.Schema 24 | import org.jooq.impl.CatalogImpl 25 | 26 | 27 | /** 28 | * This class is generated by jOOQ. 29 | */ 30 | @Suppress("UNCHECKED_CAST") 31 | open class DefaultCatalog : CatalogImpl("") { 32 | companion object { 33 | 34 | /** 35 | * The reference instance of DEFAULT_CATALOG 36 | */ 37 | val DEFAULT_CATALOG = DefaultCatalog() 38 | } 39 | 40 | /** 41 | * The schema DEFAULT_SCHEMA. 42 | */ 43 | val DEFAULT_SCHEMA get() = DefaultSchema.DEFAULT_SCHEMA 44 | 45 | override fun getSchemas(): List = listOf( 46 | DefaultSchema.DEFAULT_SCHEMA 47 | ) 48 | } 49 | -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/Conversions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.bytecode 18 | 19 | import org.jacodb.api.JcClassOrInterface 20 | import org.jacodb.api.JcMethod 21 | import org.jacodb.api.JcMethodExtFeature 22 | import org.jacodb.impl.features.JcFeaturesChain 23 | import org.jacodb.impl.types.MethodInfo 24 | 25 | fun JcClassOrInterface.toJcMethod( 26 | methodInfo: MethodInfo, 27 | featuresChain: JcFeaturesChain 28 | ): JcMethod { 29 | return JcMethodImpl(methodInfo, featuresChain, this) 30 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcParameterImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.bytecode 18 | 19 | import org.jacodb.api.JcAnnotation 20 | import org.jacodb.api.JcDeclaration 21 | import org.jacodb.api.JcMethod 22 | import org.jacodb.api.JcParameter 23 | import org.jacodb.api.TypeName 24 | import org.jacodb.impl.types.ParameterInfo 25 | import org.jacodb.impl.types.TypeNameImpl 26 | 27 | class JcParameterImpl( 28 | override val method: JcMethod, 29 | private val info: ParameterInfo 30 | ) : JcParameter { 31 | 32 | override val access: Int 33 | get() = info.access 34 | 35 | override val name: String? by lazy { 36 | info.name ?: kmParameter?.name 37 | } 38 | 39 | override val index: Int 40 | get() = info.index 41 | 42 | override val declaration: JcDeclaration 43 | get() = JcDeclarationImpl.of(method.enclosingClass.declaration.location, this) 44 | 45 | override val annotations: List 46 | get() = info.annotations.map { JcAnnotationImpl(it, method.enclosingClass.classpath) } 47 | 48 | override val type: TypeName 49 | get() = TypeNameImpl(info.type) 50 | 51 | override fun toString(): String { 52 | return "$method $name" 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/util/InstructionFilter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.cfg.util 18 | 19 | import org.jacodb.api.cfg.DefaultJcRawInstVisitor 20 | import org.jacodb.api.cfg.JcRawInst 21 | 22 | class InstructionFilter(val predicate: (JcRawInst) -> Boolean) : DefaultJcRawInstVisitor { 23 | override val defaultInstHandler: (JcRawInst) -> Boolean 24 | get() = { predicate(it) } 25 | } 26 | -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/util/printer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.cfg.util 18 | 19 | import org.objectweb.asm.tree.AbstractInsnNode 20 | import org.objectweb.asm.tree.ClassNode 21 | import org.objectweb.asm.tree.MethodNode 22 | import org.objectweb.asm.tree.TryCatchBlockNode 23 | import org.objectweb.asm.util.Textifier 24 | import org.objectweb.asm.util.TraceMethodVisitor 25 | import java.io.PrintWriter 26 | import java.io.StringWriter 27 | 28 | private val printer = Textifier() 29 | private val mp = TraceMethodVisitor(printer) 30 | 31 | fun ClassNode.print() = buildString { 32 | appendLine("Class $name") 33 | for (mn in methods) { 34 | appendLine(mn.print()) 35 | } 36 | } 37 | 38 | fun MethodNode.print() = buildString { 39 | appendLine(name) 40 | for (insn in instructions) { 41 | append(insn.print()) 42 | } 43 | for (insn in tryCatchBlocks) { 44 | append(insn.print()) 45 | } 46 | } 47 | 48 | fun AbstractInsnNode.print(): String { 49 | this.accept(mp) 50 | val sw = StringWriter() 51 | printer.print(PrintWriter(sw)) 52 | printer.getText().clear() 53 | return sw.toString() 54 | } 55 | 56 | fun TryCatchBlockNode.print() = buildString { 57 | append("${start.print().dropLast(1)} ") 58 | append("${end.print().dropLast(1)} ") 59 | append("${handler.print().dropLast(1)} ") 60 | appendLine(type ?: "java/lang/Throwable") 61 | } 62 | -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/features/Diagnostics.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("Diagnostics") 18 | 19 | package org.jacodb.impl.features 20 | 21 | 22 | import kotlinx.coroutines.GlobalScope 23 | import kotlinx.coroutines.future.future 24 | import org.jacodb.api.JcClasspath 25 | import org.jacodb.impl.storage.jooq.tables.references.CLASSES 26 | import org.jacodb.impl.storage.jooq.tables.references.SYMBOLS 27 | import org.jooq.impl.DSL 28 | 29 | 30 | /** 31 | * finds out duplicates classes 32 | * 33 | * @return map with name and count of classes 34 | */ 35 | suspend fun JcClasspath.duplicatedClasses(): Map { 36 | db.awaitBackgroundJobs() 37 | return db.persistence.read { 38 | it.select(SYMBOLS.NAME, DSL.count(SYMBOLS.NAME)).from(CLASSES) 39 | .join(SYMBOLS).on(SYMBOLS.ID.eq(CLASSES.NAME)) 40 | .where(CLASSES.LOCATION_ID.`in`(registeredLocations.map { it.id })) 41 | .groupBy(SYMBOLS.NAME) 42 | .having(DSL.count(SYMBOLS.NAME).greaterThan(1)) 43 | .fetch() 44 | .map { (name, count) -> name!! to count!!} 45 | .toMap() 46 | } 47 | 48 | } 49 | 50 | fun JcClasspath.asyncDuplicatedClasses() = GlobalScope.future { duplicatedClasses() } 51 | -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/features/JcFeaturesChain.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.features 18 | 19 | import org.jacodb.api.JcClasspathFeature 20 | import org.jacodb.api.JcFeatureEvent 21 | import org.jacodb.api.JcLookupExtFeature 22 | 23 | class JcFeaturesChain(val features: List) { 24 | 25 | val classLookups = features.filterIsInstance() 26 | 27 | inline fun run(call: (T) -> Unit) { 28 | for (feature in features) { 29 | if (feature is T) { 30 | call(feature) 31 | } 32 | } 33 | } 34 | 35 | inline fun call(call: (T) -> W?): W? { 36 | var result: W? = null 37 | var event: JcFeatureEvent? = null 38 | for (feature in features) { 39 | if (feature is T) { 40 | result = call(feature) 41 | if (result != null) { 42 | event = feature.event(result) 43 | break 44 | } 45 | } 46 | } 47 | if (result != null && event != null) { 48 | for (feature in features) { 49 | feature.on(event) 50 | } 51 | } 52 | return result 53 | } 54 | } 55 | 56 | class JcFeatureEventImpl( 57 | override val feature: JcClasspathFeature, 58 | override val result: Any, 59 | ) : JcFeatureEvent -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/features/UsageRequest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.features 18 | 19 | import kotlinx.serialization.Serializable 20 | import org.jacodb.api.ClassSource 21 | 22 | @Serializable 23 | data class UsageFeatureRequest( 24 | val methodName: String?, 25 | val description: String?, 26 | val field: String?, 27 | val opcodes: Collection, 28 | val className: Set 29 | ) : java.io.Serializable 30 | 31 | class UsageFeatureResponse( 32 | val source: ClassSource, 33 | val offsets: ShortArray 34 | ) 35 | 36 | -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/StringConcatSimplifier.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.features.classpaths 18 | 19 | import org.jacodb.api.JcInstExtFeature 20 | import org.jacodb.api.JcMethod 21 | import org.jacodb.api.JcMethodExtFeature 22 | import org.jacodb.api.cfg.JcInst 23 | import org.jacodb.api.cfg.JcInstList 24 | import org.jacodb.impl.analysis.impl.StringConcatSimplifierTransformer 25 | 26 | object StringConcatSimplifier : JcInstExtFeature, JcMethodExtFeature { 27 | 28 | override fun transformInstList(method: JcMethod, list: JcInstList): JcInstList { 29 | return StringConcatSimplifierTransformer(method.enclosingClass.classpath, list).transform() 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/virtual/JcVirtualField.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.features.classpaths.virtual 18 | 19 | import org.jacodb.api.JcAnnotation 20 | import org.jacodb.api.JcClassOrInterface 21 | import org.jacodb.api.JcDeclaration 22 | import org.jacodb.api.JcField 23 | import org.jacodb.api.TypeName 24 | import org.jacodb.impl.bytecode.JcDeclarationImpl 25 | import org.objectweb.asm.Opcodes 26 | 27 | interface JcVirtualField : JcField { 28 | fun bind(clazz: JcClassOrInterface) 29 | 30 | } 31 | 32 | open class JcVirtualFieldImpl( 33 | override val name: String, 34 | override val access: Int = Opcodes.ACC_PUBLIC, 35 | override val type: TypeName, 36 | ) : JcVirtualField { 37 | override val declaration: JcDeclaration 38 | get() = JcDeclarationImpl.of(enclosingClass.declaration.location, this) 39 | 40 | override lateinit var enclosingClass: JcClassOrInterface 41 | 42 | override fun bind(clazz: JcClassOrInterface) { 43 | this.enclosingClass = clazz 44 | } 45 | 46 | override val signature: String? 47 | get() = null 48 | override val annotations: List 49 | get() = emptyList() 50 | 51 | override fun toString(): String { 52 | return "virtual $enclosingClass#$name" 53 | } 54 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/fs/AbstractByteCodeLocation.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.fs 18 | 19 | import com.google.common.hash.Hashing 20 | import org.jacodb.api.JcByteCodeLocation 21 | import java.io.File 22 | import java.nio.charset.StandardCharsets 23 | 24 | 25 | abstract class AbstractByteCodeLocation(override val jarOrFolder: File) : JcByteCodeLocation { 26 | 27 | override val path: String 28 | get() = jarOrFolder.absolutePath 29 | 30 | abstract fun currentHash(): String 31 | 32 | override fun isChanged() = fileSystemId != currentHash() 33 | 34 | 35 | protected val String.shaHash: String 36 | get() { 37 | return Hashing.sha256() 38 | .hashString(this, StandardCharsets.UTF_8) 39 | .toString(); 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/fs/ByteCodeLoaderImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.fs 18 | 19 | import org.jacodb.api.ClassSource 20 | import org.jacodb.api.RegisteredLocation 21 | 22 | val RegisteredLocation.sources: List 23 | get() { 24 | return jcLocation?.classes?.map { 25 | ClassSourceImpl(this, it.key, it.value) 26 | }.orEmpty() 27 | } 28 | 29 | val RegisteredLocation.lazySources: List 30 | get() { 31 | val classNames = jcLocation?.classNames ?: return emptyList() 32 | if (classNames.any { it.startsWith("java.") }) { 33 | return sources 34 | } 35 | return classNames.map { 36 | LazyClassSourceImpl(this, it) 37 | } 38 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/fs/ByteCodeLocations.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.fs 18 | 19 | import mu.KLogging 20 | import org.jacodb.api.JavaVersion 21 | import org.jacodb.api.JcByteCodeLocation 22 | import java.io.File 23 | 24 | val logger = object : KLogging() {}.logger 25 | 26 | fun File.asByteCodeLocation(runtimeVersion: JavaVersion, isRuntime: Boolean = false): JcByteCodeLocation { 27 | if (!exists()) { 28 | throw IllegalArgumentException("file $absolutePath doesn't exist") 29 | } 30 | if (isFile && name.endsWith(".jar") || name.endsWith(".jmod")) { 31 | return JarLocation(this, isRuntime, runtimeVersion) 32 | } else if (!isFile) { 33 | return BuildFolderLocation(this) 34 | } 35 | throw IllegalArgumentException("file $absolutePath is not jar-file nor build dir folder") 36 | } 37 | 38 | fun List.filterExisted(): List = filter { file -> 39 | file.exists().also { 40 | if (!it) { 41 | logger.warn("${file.absolutePath} doesn't exists. make sure there is no mistake") 42 | } 43 | } 44 | } 45 | 46 | fun String.matchesOneOf(loadClassesOnlyFrom: List?): Boolean { 47 | loadClassesOnlyFrom ?: return true 48 | return loadClassesOnlyFrom.any { 49 | startsWith(it) 50 | } 51 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/fs/JavaVersionImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.fs 18 | 19 | import org.jacodb.api.JavaVersion 20 | 21 | private class JavaVersionImpl(override val majorVersion: Int) : JavaVersion 22 | 23 | fun parseRuntimeVersion(version: String): JavaVersion { 24 | return when { 25 | version.startsWith("1.") -> JavaVersionImpl(version.substring(2, 3).toInt()) 26 | else -> { 27 | val dot = version.indexOf(".") 28 | if (dot != -1) { 29 | JavaVersionImpl(version.substring(0, dot).toInt()) 30 | } else { 31 | JavaVersionImpl(8) 32 | } 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/jacodb.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @file:JvmName("JacoDB") 18 | 19 | package org.jacodb.impl 20 | 21 | import kotlinx.coroutines.GlobalScope 22 | import kotlinx.coroutines.future.future 23 | import org.jacodb.api.JcDatabase 24 | import org.jacodb.impl.fs.JavaRuntime 25 | 26 | suspend fun jacodb(builder: JcSettings.() -> Unit): JcDatabase { 27 | return jacodb(JcSettings().also(builder)) 28 | } 29 | 30 | suspend fun jacodb(settings: JcSettings): JcDatabase { 31 | val featureRegistry = FeaturesRegistry(settings.features) 32 | val javaRuntime = JavaRuntime(settings.jre) 33 | val persistence = (settings.persistentType ?: PredefinedPersistenceType.SQLITE) 34 | .newPersistence(javaRuntime, featureRegistry, settings) 35 | return JcDatabaseImpl( 36 | javaRuntime = javaRuntime, 37 | persistence = persistence, 38 | featureRegistry = featureRegistry, 39 | settings = settings 40 | ).also { 41 | it.restore() 42 | it.afterStart() 43 | } 44 | } 45 | 46 | /** bridge for Java */ 47 | fun async(settings: JcSettings) = GlobalScope.future { jacodb(settings) } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/storage/Caches.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.storage 18 | 19 | import com.google.common.cache.Cache 20 | import com.google.common.cache.CacheBuilder 21 | import java.time.Duration 22 | 23 | 24 | fun cacheOf(size: Long): Cache { 25 | return CacheBuilder.newBuilder() 26 | .maximumSize(size) 27 | .expireAfterAccess(Duration.ofSeconds(10)).build() 28 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/storage/DataStorageException.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.storage 18 | 19 | class DataStorageException(msg: String) : Exception(msg) -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/storage/Enums.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.storage 18 | 19 | enum class AnnotationValueKind { 20 | BOOLEAN, 21 | BYTE, 22 | CHAR, 23 | SHORT, 24 | INT, 25 | FLOAT, 26 | LONG, 27 | DOUBLE, 28 | STRING; 29 | 30 | companion object { 31 | fun serialize(value: Any): String { 32 | return when (value) { 33 | is String -> value 34 | is Short -> value.toString() 35 | is Char -> value.toString() 36 | is Long -> value.toString() 37 | is Int -> value.toString() 38 | is Float -> value.toString() 39 | is Double -> value.toString() 40 | is Byte -> value.toString() 41 | is Boolean -> value.toString() 42 | else -> throw IllegalStateException("Unknown type ${value.javaClass}") 43 | } 44 | } 45 | } 46 | 47 | } 48 | 49 | 50 | enum class LocationState { 51 | INITIAL, 52 | AWAITING_INDEXING, 53 | PROCESSED, 54 | OUTDATED 55 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/types/JcTypedMethodParameterImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.types 18 | 19 | import org.jacodb.api.* 20 | import org.jacodb.api.ext.isNullable 21 | import org.jacodb.impl.bytecode.JcAnnotationImpl 22 | import org.jacodb.impl.bytecode.JcMethodImpl 23 | 24 | class JcTypedMethodParameterImpl( 25 | override val enclosingMethod: JcTypedMethod, 26 | private val parameter: JcParameter, 27 | private val jvmType: JvmType?, 28 | private val substitutor: JcSubstitutor 29 | ) : JcTypedMethodParameter { 30 | 31 | val classpath = enclosingMethod.method.enclosingClass.classpath 32 | 33 | override val type: JcType 34 | get() { 35 | val typeName = parameter.type.typeName 36 | val type = jvmType?.let { 37 | classpath.typeOf(substitutor.substitute(jvmType)) 38 | } ?: classpath.findTypeOrNull(typeName) 39 | ?.copyWithAnnotations( 40 | (enclosingMethod.method as? JcMethodImpl)?.parameterTypeAnnotationInfos(parameter.index)?.map { JcAnnotationImpl(it, classpath) } ?: listOf() 41 | ) ?: typeName.throwClassNotFound() 42 | 43 | return parameter.isNullable?.let { 44 | (type as? JcRefType)?.copyWithNullability(it) 45 | } ?: type 46 | } 47 | 48 | override val name: String? 49 | get() = parameter.name 50 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/types/signature/JvmTypeParameterDeclaration.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.types.signature 18 | 19 | import org.jacodb.api.JcAccessible 20 | import org.jacodb.api.JvmType 21 | import org.jacodb.api.JvmTypeParameterDeclaration 22 | 23 | internal class JvmTypeParameterDeclarationImpl( 24 | override val symbol: String, 25 | override val owner: JcAccessible, 26 | override val bounds: List? = null 27 | ) : JvmTypeParameterDeclaration { 28 | 29 | 30 | override fun toString(): String { 31 | return "$symbol : ${bounds?.joinToString { it.displayName }}" 32 | } 33 | 34 | override fun equals(other: Any?): Boolean { 35 | if (this === other) return true 36 | if (javaClass != other?.javaClass) return false 37 | 38 | other as JvmTypeParameterDeclarationImpl 39 | 40 | if (symbol != other.symbol) return false 41 | if (owner != other.owner) return false 42 | 43 | return true 44 | } 45 | 46 | override fun hashCode(): Int { 47 | var result = symbol.hashCode() 48 | result = 31 * result + owner.hashCode() 49 | return result 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/types/signature/RecordSignature.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.types.signature 18 | 19 | import org.jacodb.api.JvmType 20 | import org.jacodb.api.Malformed 21 | import org.jacodb.api.Pure 22 | import org.jacodb.api.RecordComponentResolution 23 | import org.objectweb.asm.signature.SignatureReader 24 | 25 | internal class RecordSignature : TypeRegistrant { 26 | 27 | private lateinit var recordComponentType: JvmType 28 | 29 | override fun register(token: JvmType) { 30 | recordComponentType = token 31 | } 32 | 33 | protected fun resolve(): RecordComponentResolution { 34 | return RecordComponentResolutionImpl(recordComponentType) 35 | } 36 | 37 | companion object { 38 | fun of(signature: String?): RecordComponentResolution { 39 | signature ?: return Pure 40 | val signatureReader = SignatureReader(signature) 41 | val visitor = RecordSignature() 42 | return try { 43 | signatureReader.acceptType(TypeExtractor(visitor)) 44 | visitor.resolve() 45 | } catch (ignored: RuntimeException) { 46 | Malformed 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/types/signature/Resolutions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.types.signature 18 | 19 | import org.jacodb.api.* 20 | 21 | internal class FieldResolutionImpl(val fieldType: JvmType) : FieldResolution 22 | 23 | internal class RecordComponentResolutionImpl(val recordComponentType: JvmType) : RecordComponentResolution 24 | 25 | internal class MethodResolutionImpl( 26 | val returnType: JvmType, 27 | val parameterTypes: List, 28 | val exceptionTypes: List, 29 | val typeVariables: List 30 | ) : MethodResolution 31 | 32 | internal class TypeResolutionImpl( 33 | val superClass: JvmType, 34 | val interfaceType: List, 35 | val typeVariables: List 36 | ) : TypeResolution 37 | 38 | -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/vfs/ClassTreeListener.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.vfs 18 | 19 | interface ClassTreeListener { 20 | 21 | /** 22 | * method called when bytecode is read from file 23 | * @param nodeWithLoadedByteCode - class node with fully loaded node 24 | */ 25 | suspend fun notifyOnByteCodeLoaded(nodeWithLoadedByteCode: ClassVfsItem, globalClassVFS: GlobalClassesVfs) 26 | 27 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/vfs/ClassVfsItem.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.vfs 18 | 19 | import org.jacodb.api.ClassSource 20 | 21 | class ClassVfsItem( 22 | override val name: String, 23 | packageNode: PackageVfsItem, 24 | internal val source: ClassSource 25 | ) : AbstractVfsItem(name, packageNode) { 26 | 27 | val location get() = source.location 28 | 29 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/vfs/ClasspathVfs.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.vfs 18 | 19 | import org.jacodb.api.RegisteredLocation 20 | import org.jacodb.impl.LocationsRegistrySnapshot 21 | 22 | /** 23 | * ClassTree view limited by number of `locations` 24 | */ 25 | class ClasspathVfs( 26 | private val globalClassVFS: GlobalClassesVfs, 27 | locations: List 28 | ) { 29 | 30 | constructor(globalClassVFS: GlobalClassesVfs, locationsRegistrySnapshot: LocationsRegistrySnapshot) : this( 31 | globalClassVFS, 32 | locationsRegistrySnapshot.locations 33 | ) 34 | 35 | private val locationIds: Set = locations.map { it.id }.toHashSet() 36 | 37 | fun firstClassOrNull(fullName: String): ClassVfsItem? { 38 | return globalClassVFS.firstClassNodeOrNull(fullName) { 39 | locationIds.contains(it) 40 | } 41 | } 42 | 43 | fun findClassNodes(fullName: String): List { 44 | return globalClassVFS.findClassNodes(fullName) { 45 | locationIds.contains(it) 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/kotlin/org/jacodb/impl/vfs/Vfs.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.impl.vfs 18 | 19 | import org.jacodb.api.RegisteredLocation 20 | 21 | abstract class AbstractVfsItem>(open val name: String?, val parent: T?) { 22 | 23 | val fullName: String by lazy { 24 | val reversedNames = arrayListOf() 25 | var node: AbstractVfsItem<*>? = this 26 | while (node != null) { 27 | node.name?.let { 28 | reversedNames.add(it) 29 | } 30 | node = node.parent 31 | } 32 | reversedNames.reversed().joinToString(".") 33 | } 34 | 35 | } 36 | 37 | interface VfsVisitor { 38 | 39 | fun visitPackage(packageItem: PackageVfsItem) {} 40 | } 41 | 42 | class RemoveLocationsVisitor( 43 | private val locations: List, 44 | private val ignoredPackages: List = emptyList() 45 | ) : VfsVisitor { 46 | 47 | override fun visitPackage(packageItem: PackageVfsItem) { 48 | val name = packageItem.fullName + "." 49 | if (ignoredPackages.any { name.startsWith(it) }) { 50 | return 51 | } 52 | locations.forEach { 53 | packageItem.removeClasses(it.id) 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /jacodb-core/src/main/resources/jacodb.properties: -------------------------------------------------------------------------------- 1 | jacodb.version=${version} -------------------------------------------------------------------------------- /jacodb-core/src/main/resources/sqlite/add-indexes.sql: -------------------------------------------------------------------------------- 1 | CREATE INDEX IF NOT EXISTS "Classes_name" ON "Classes" ("name"); 2 | 3 | CREATE INDEX IF NOT EXISTS "Classes_outerMethodId" ON "Classes" ("outer_method"); 4 | CREATE INDEX IF NOT EXISTS "ClassInnerClasses_classId" ON "ClassInnerClasses" ("class_id"); 5 | CREATE INDEX IF NOT EXISTS "ClassInnerClasses_classId" ON "ClassInnerClasses" ("class_id"); 6 | CREATE INDEX IF NOT EXISTS "ClassInnerClasses_innerClassId" ON "ClassInnerClasses" ("inner_class_id"); 7 | 8 | CREATE INDEX IF NOT EXISTS "ClassHierarchies_classId" ON "ClassHierarchies" ("class_id"); 9 | CREATE INDEX IF NOT EXISTS "ClassHierarchies_superId" ON "ClassHierarchies" ("super_id"); 10 | 11 | CREATE INDEX IF NOT EXISTS "Annotations_classId" ON "Annotations" ("class_id"); 12 | CREATE INDEX IF NOT EXISTS "Annotations_fieldId" ON "Annotations" ("field_id"); 13 | CREATE INDEX IF NOT EXISTS "Annotations_methodId" ON "Annotations" ("method_id"); 14 | CREATE INDEX IF NOT EXISTS "Annotations_paramsId" ON "Annotations" ("param_id"); 15 | 16 | CREATE INDEX IF NOT EXISTS "Classes_location" ON "Classes" ("location_id"); 17 | CREATE INDEX IF NOT EXISTS "Fields_classId" ON "Fields" ("class_id"); 18 | CREATE INDEX IF NOT EXISTS "Methods_classId" ON "Methods" ("class_id"); 19 | 20 | CREATE INDEX IF NOT EXISTS "MethodParameters_methodId" ON "MethodParameters" ("method_id"); 21 | 22 | CREATE UNIQUE INDEX IF NOT EXISTS "Symbols_name" ON "Symbols" ("name"); 23 | CREATE UNIQUE INDEX IF NOT EXISTS "Bytecodelocations_hash" ON "BytecodeLocations" ("uniqueId"); 24 | CREATE UNIQUE INDEX IF NOT EXISTS "Methods_class_id_name_desc" ON "Methods" ("class_id", "name", "desc"); 25 | CREATE UNIQUE INDEX IF NOT EXISTS "Fields_class_id_name" ON "Fields" ("class_id", "name"); 26 | CREATE INDEX IF NOT EXISTS "Class Hierarchies" on "ClassHierarchies" ("super_id"); 27 | 28 | PRAGMA foreign_keys = ON; -------------------------------------------------------------------------------- /jacodb-core/src/main/resources/sqlite/drop-schema.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS "BytecodeLocations"; 2 | DROP TABLE IF EXISTS "Symbols"; 3 | DROP TABLE IF EXISTS "OuterClasses"; 4 | DROP TABLE IF EXISTS "Methods"; 5 | DROP TABLE IF EXISTS "Classes"; 6 | DROP TABLE IF EXISTS "ClassHierarchies"; 7 | DROP TABLE IF EXISTS "ClassInnerClasses"; 8 | DROP TABLE IF EXISTS "MethodParameters"; 9 | DROP TABLE IF EXISTS "Fields"; 10 | DROP TABLE IF EXISTS "Annotations"; 11 | DROP TABLE IF EXISTS "AnnotationValues"; 12 | DROP INDEX IF EXISTS "Symbols_name"; 13 | DROP INDEX IF EXISTS "Classes_name"; 14 | DROP INDEX IF EXISTS "Methods_class_id_name_desc"; 15 | DROP INDEX IF EXISTS "Fields_class_id_name"; 16 | DROP INDEX IF EXISTS "Class Hierarchies"; 17 | -------------------------------------------------------------------------------- /jacodb-core/src/main/resources/sqlite/empty.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/jacodb-core/src/main/resources/sqlite/empty.db -------------------------------------------------------------------------------- /jacodb-core/src/main/resources/sqlite/usages/add-indexes.sql: -------------------------------------------------------------------------------- 1 | CREATE INDEX IF NOT EXISTS 'CallsSearch' ON Calls(opcode, location_id, callee_class_name, callee_name, callee_desc_hash); 2 | -------------------------------------------------------------------------------- /jacodb-core/src/main/resources/sqlite/usages/create-schema.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS "Calls"( 2 | "callee_class_name" VARCHAR(256) NOT NULL, 3 | "callee_name" VARCHAR(256) NOT NULL, 4 | "callee_desc_hash" BIGINT, 5 | "opcode" INTEGER, 6 | "caller_class_name" VARCHAR(256) NOT NULL, 7 | "caller_method_offsets" BLOB, 8 | "location_id" BIGINT NOT NULL, 9 | CONSTRAINT "fk_location_id" FOREIGN KEY ("location_id") REFERENCES "BytecodeLocations" ("id") ON DELETE CASCADE ON UPDATE RESTRICT 10 | ); -------------------------------------------------------------------------------- /jacodb-core/src/main/resources/sqlite/usages/drop-schema.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS "Calls"; 2 | DROP INDEX IF EXISTS "CallsSearch"; -------------------------------------------------------------------------------- /jacodb-core/src/test/java/org/jacodb/testing/JavaApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing; 18 | 19 | import org.jacodb.api.JcDatabase; 20 | import org.jacodb.api.cfg.JcArgument; 21 | import org.jacodb.api.cfg.JcExpr; 22 | import org.jacodb.api.cfg.TypedExprResolver; 23 | import org.jacodb.impl.JacoDB; 24 | import org.jacodb.impl.JcCacheSettings; 25 | import org.jacodb.impl.JcSettings; 26 | import org.jacodb.impl.features.Usages; 27 | import org.jetbrains.annotations.NotNull; 28 | 29 | import java.time.Duration; 30 | import java.time.temporal.ChronoUnit; 31 | 32 | public class JavaApi { 33 | private static class ArgumentResolver extends TypedExprResolver { 34 | 35 | @Override 36 | public void ifMatches(@NotNull JcExpr jcExpr) { 37 | if (jcExpr instanceof JcArgument) { 38 | getResult().add((JcArgument) jcExpr); 39 | } 40 | } 41 | 42 | } 43 | 44 | public static void cacheSettings() { 45 | new JcCacheSettings().types(10, Duration.of(1, ChronoUnit.MINUTES)); 46 | } 47 | 48 | public static void getDatabase() { 49 | try { 50 | JcDatabase instance = JacoDB.async(new JcSettings().installFeatures(Usages.INSTANCE)).get(); 51 | } catch (Exception e) { 52 | throw new RuntimeException(e); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /jacodb-core/src/test/kotlin/org/jacodb/testing/Bar.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing 18 | 19 | class BarKt -------------------------------------------------------------------------------- /jacodb-core/src/test/kotlin/org/jacodb/testing/JavaVersionTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing 18 | 19 | import org.jacodb.impl.JcSettings 20 | import org.jacodb.impl.fs.JavaRuntime 21 | import org.junit.jupiter.api.Assertions.assertEquals 22 | import org.junit.jupiter.api.Test 23 | import org.junit.jupiter.api.condition.EnabledOnJre 24 | import org.junit.jupiter.api.condition.JRE 25 | 26 | class JavaVersionTest { 27 | 28 | @Test 29 | @EnabledOnJre(JRE.JAVA_11) 30 | fun `java version should be proper for 11 java`() { 31 | assertEquals(11, JavaRuntime(JcSettings().useProcessJavaRuntime().jre).version.majorVersion) 32 | } 33 | @Test 34 | @EnabledOnJre(JRE.JAVA_8) 35 | fun `java version should be proper for 8 java`() { 36 | assertEquals(8, JavaRuntime(JcSettings().useProcessJavaRuntime().jre).version.majorVersion) 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /jacodb-core/src/test/kotlin/org/jacodb/testing/SubclassesTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing 18 | 19 | import kotlinx.coroutines.runBlocking 20 | import org.jacodb.api.JcClasspath 21 | import org.jacodb.api.ext.JAVA_OBJECT 22 | import org.jacodb.impl.features.hierarchyExt 23 | import org.junit.jupiter.api.AfterEach 24 | import org.junit.jupiter.api.Assertions 25 | import org.junit.jupiter.api.Test 26 | 27 | @LifecycleTest 28 | class SubclassesTest : BaseTest() { 29 | 30 | companion object : WithGlobalDB() 31 | 32 | private val withDB = WithDB() 33 | 34 | private val anotherDb = withDB.db 35 | private val anotherCp: JcClasspath by lazy { 36 | runBlocking { 37 | anotherDb.awaitBackgroundJobs() 38 | anotherDb.classpath(allClasspath) 39 | } 40 | } 41 | 42 | @Test 43 | fun `Object subclasses should be the same`() { 44 | runBlocking { 45 | val hierarchy = cp.hierarchyExt() 46 | val anotherHierarchy = anotherCp.hierarchyExt() 47 | Assertions.assertEquals( 48 | hierarchy.findSubClasses(JAVA_OBJECT, false, includeOwn = true).count(), 49 | anotherHierarchy.findSubClasses(JAVA_OBJECT, false, includeOwn = true).count() 50 | ) 51 | } 52 | } 53 | 54 | @AfterEach 55 | fun `cleanup another db`() = runBlocking { 56 | withDB.cleanup() 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /jacodb-core/src/test/kotlin/org/jacodb/testing/persistence/RestoredDBTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.persistence 18 | 19 | import kotlinx.coroutines.runBlocking 20 | import org.jacodb.api.JcClasspath 21 | import org.jacodb.api.ext.HierarchyExtension 22 | import org.jacodb.impl.features.hierarchyExt 23 | import org.jacodb.testing.LifecycleTest 24 | import org.jacodb.testing.WithRestoredDB 25 | import org.jacodb.testing.allClasspath 26 | import org.jacodb.testing.tests.DatabaseEnvTest 27 | import org.jacodb.testing.withDB 28 | 29 | @LifecycleTest 30 | class RestoredDBTest : DatabaseEnvTest() { 31 | 32 | companion object : WithRestoredDB() 33 | 34 | override val cp: JcClasspath by lazy { 35 | runBlocking { 36 | val withDB = this@RestoredDBTest.javaClass.withDB 37 | withDB.db.classpath(allClasspath) 38 | } 39 | } 40 | 41 | override val hierarchyExt: HierarchyExtension by lazy { runBlocking { cp.hierarchyExt() } } 42 | 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /jacodb-core/src/test/kotlin/org/jacodb/testing/tree/DummyCodeLocation.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.tree 18 | 19 | import org.jacodb.api.JcByteCodeLocation 20 | import org.jacodb.api.LocationType 21 | import org.jacodb.api.RegisteredLocation 22 | import org.jacodb.impl.storage.longHash 23 | import java.io.File 24 | 25 | open class DummyCodeLocation(private val name: String) : JcByteCodeLocation, RegisteredLocation { 26 | 27 | override val id: Long 28 | get() = name.longHash 29 | 30 | override val fileSystemId: String 31 | get() = name 32 | 33 | override val isRuntime: Boolean 34 | get() = false 35 | 36 | override val jcLocation: JcByteCodeLocation 37 | get() = this 38 | 39 | override val type = LocationType.APP 40 | 41 | override val classes: Map? 42 | get() = null 43 | 44 | override val jarOrFolder: File 45 | get() = TODO("Not yet implemented") 46 | override val path: String 47 | get() = TODO("") 48 | 49 | override fun isChanged() = false 50 | 51 | override fun createRefreshed() = this 52 | 53 | override fun resolve(classFullName: String) = null 54 | 55 | override val classNames: Set 56 | get() = emptySet() 57 | 58 | } 59 | 60 | -------------------------------------------------------------------------------- /jacodb-core/src/test/kotlin/org/jacodb/testing/types/BaseTypesTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.types 18 | 19 | import org.jacodb.api.JcClassType 20 | import org.jacodb.api.JcType 21 | import org.jacodb.testing.BaseTest 22 | import org.jacodb.testing.WithGlobalDB 23 | import org.junit.jupiter.api.Assertions.* 24 | 25 | abstract class BaseTypesTest : BaseTest() { 26 | 27 | companion object : WithGlobalDB() 28 | 29 | protected inline fun findType(): JcClassType { 30 | val found = cp.findTypeOrNull(T::class.java.name) 31 | assertNotNull(found) 32 | return found!!.assertIs() 33 | } 34 | 35 | protected fun JcType?.assertIsClass(): JcClassType { 36 | assertNotNull(this) 37 | return this!!.assertIs() 38 | } 39 | 40 | protected inline fun JcType?.assertClassType(): JcClassType { 41 | val expected = findType() 42 | assertEquals( 43 | expected.jcClass.name, 44 | (this as? JcClassType)?.jcClass?.name, 45 | "Expected ${expected.jcClass.name} but got ${this?.typeName}" 46 | ) 47 | return this as JcClassType 48 | } 49 | 50 | 51 | protected inline fun Any.assertIs(): T { 52 | return assertInstanceOf(T::class.java, this) 53 | } 54 | } -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/samples/GenericsApi.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/jacodb-core/src/test/resources/samples/GenericsApi.class -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/samples/GenericsApiConsumer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/jacodb-core/src/test/resources/samples/GenericsApiConsumer.class -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/samples/PhantomClassSubclass.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/jacodb-core/src/test/resources/samples/PhantomClassSubclass.class -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/samples/PhantomCodeConsumer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/jacodb-core/src/test/resources/samples/PhantomCodeConsumer.class -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/samples/PhantomDeclaration.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/jacodb-core/src/test/resources/samples/PhantomDeclaration.class -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/samples/PhantomDeclarationConsumer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/jacodb-core/src/test/resources/samples/PhantomDeclarationConsumer.class -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/samples/TestLDC.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/jacodb-core/src/test/resources/samples/TestLDC.class -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/samples/VirtualInstructions.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/jacodb-core/src/test/resources/samples/VirtualInstructions.class -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/src/GenericsApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import java.io.Closeable; 18 | 19 | public class GenericsApi { 20 | 21 | public T closeable; 22 | 23 | public GenericsApi(T closeable) { 24 | this.closeable = closeable; 25 | } 26 | 27 | public GenericsApi call(GenericsApi arg) { 28 | return new GenericsApi<>(arg.closeable); 29 | } 30 | 31 | public GenericsApi callGeneric(GenericsApi arg) { 32 | return new GenericsApi<>(arg.closeable); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/src/PhantomClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | public class PhantomClass { 18 | 19 | public int intField; 20 | public String stringField; 21 | 22 | public void run() { 23 | } 24 | 25 | public static void staticRun() { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/src/PhantomClassSubclass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | public class PhantomClassSubclass extends PhantomClass { 18 | 19 | @Override 20 | public void run() { 21 | super.run(); 22 | System.out.println(super.intField); 23 | staticRun(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/src/PhantomCodeConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | public class PhantomCodeConsumer { 18 | 19 | private final PhantomClass clazz = new PhantomClass(); 20 | 21 | public void fieldRef() { 22 | System.out.println(clazz.intField); 23 | System.out.println(clazz.stringField); 24 | } 25 | 26 | public void methodRef() { 27 | clazz.run(); 28 | } 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/src/PhantomDeclaration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | public class PhantomDeclaration { 18 | int x = 0; 19 | int y = 0; 20 | 21 | public void run() { 22 | System.out.println("Hello world"); 23 | } 24 | 25 | public void runSomething() { 26 | System.out.println("Hello world"); 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/src/PhantomDeclarationConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | public class PhantomDeclarationConsumer { 18 | 19 | PhantomDeclaration f = new PhantomDeclaration(); 20 | 21 | public void call() { 22 | System.out.println(f.y); 23 | f.runSomething(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/src/PhantomInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | public interface PhantomInterface { 18 | 19 | static void staticFoo() { 20 | System.out.println("static foo"); 21 | } 22 | 23 | void foo(); 24 | } 25 | -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/src/PhantomInterfaceConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | public class PhantomInterfaceConsumer { 18 | 19 | private final PhantomInterface iface = new PhantomInterfaceImpl(); 20 | 21 | public void methodRef() { 22 | iface.foo(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /jacodb-core/src/test/resources/src/PhantomInterfaceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | public class PhantomInterfaceImpl implements PhantomInterface { 18 | 19 | @Override 20 | public void foo() { 21 | PhantomInterface.staticFoo(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/Bar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing; 18 | 19 | public class Bar { 20 | byte[] byteArray = new byte[19]; 21 | Object[] objectArray = new Object[19]; 22 | Object[][] objectObjectArray = new Object[19][]; 23 | 24 | public byte[] smth(byte[] another) { 25 | return another; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/Common.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing; 18 | 19 | public class Common { 20 | 21 | public interface CommonInterface { 22 | 23 | default void defaultMethod() { 24 | System.out.println("Hello"); 25 | } 26 | } 27 | 28 | public static class CommonClass implements CommonInterface { 29 | 30 | public void run() { 31 | defaultMethod(); 32 | } 33 | 34 | } 35 | 36 | public static class Common1 { 37 | public int publicField; 38 | protected int protectedField; 39 | private int privateField; 40 | int packageField; 41 | 42 | public void publicMethod() { 43 | } 44 | 45 | protected void protectedMethod() { 46 | } 47 | 48 | private void privateMethod() { 49 | } 50 | 51 | void packageMethod() { 52 | } 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/analysis/SqlInjectionExamples.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.analysis; 18 | 19 | import java.sql.Connection; 20 | import java.sql.DriverManager; 21 | import java.sql.SQLException; 22 | import java.sql.Statement; 23 | 24 | @SuppressWarnings("ALL") 25 | public class SqlInjectionExamples { 26 | 27 | void bad() { 28 | String data = System.getenv("USER"); 29 | try ( 30 | Connection dbConnection = DriverManager.getConnection("", "", ""); 31 | Statement sqlStatement = dbConnection.createStatement(); 32 | ) { 33 | boolean result = sqlStatement.execute("insert into users (status) values ('updated') where name='" + data + "'"); 34 | 35 | if (result) { 36 | System.out.println("User '" + data + "' updated successfully"); 37 | } else { 38 | System.out.println("Unable to update records for user '" + data + "'"); 39 | } 40 | } catch (SQLException e) { 41 | System.err.println("Error: " + e); 42 | } finally { 43 | System.out.println("OK!"); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/builders/Hierarchy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.builders; 18 | 19 | public class Hierarchy { 20 | 21 | public interface HierarchyInterface { 22 | } 23 | 24 | public static class HierarchyImpl1 implements HierarchyInterface { 25 | } 26 | 27 | public HierarchyImpl1 build() { 28 | return new HierarchyImpl1(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/builders/Interfaces.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.builders; 18 | 19 | import java.util.List; 20 | 21 | public class Interfaces { 22 | 23 | public static interface Interface { 24 | 25 | } 26 | 27 | public static class Impl1 implements Interface { 28 | } 29 | 30 | public static class Impl2 extends Impl1 { 31 | } 32 | 33 | 34 | 35 | public Interface build1() { 36 | return new Impl1(); 37 | } 38 | 39 | public Interface build2(Impl2 impl2) { 40 | return impl2; 41 | } 42 | 43 | public Interface build3(List list) { 44 | return list.get(0); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/builders/Simple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.builders; 18 | 19 | public class Simple { 20 | 21 | public static class SimpleBuilder { 22 | 23 | private Simple property; 24 | 25 | public Simple getProperty() { 26 | return property; 27 | } 28 | 29 | public void setProperty(Simple property) { 30 | this.property = property; 31 | } 32 | 33 | public Simple build() { 34 | return new Simple(); 35 | } 36 | 37 | public Simple justReturnThis(Simple simple) { 38 | return simple; 39 | } 40 | } 41 | 42 | private Simple() { 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/ArgAssignmentExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg; 18 | 19 | public class ArgAssignmentExample { 20 | private static class X { 21 | public final int a = 0; 22 | } 23 | 24 | private static X sample(X arg) { 25 | if (arg.a == 0) { 26 | arg = null; 27 | } 28 | return arg; 29 | } 30 | 31 | public String box() { 32 | X result = sample(new X()); 33 | return result == null ? "OK" : "BAD"; 34 | } 35 | } -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/Conditionals.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Collections; 21 | import java.util.List; 22 | import java.util.Random; 23 | 24 | public class Conditionals { 25 | void main(int x, int y) { 26 | if (x < 0) { 27 | System.out.println("< 0"); 28 | } 29 | if (x <= 0) { 30 | System.out.println("<= 0"); 31 | } 32 | if (x < y) { 33 | System.out.println("<"); 34 | } 35 | if (x <= y) { 36 | System.out.println("<="); 37 | } 38 | } 39 | 40 | public static Object conditionInFor() { 41 | Random rnd = new Random(); 42 | List list = new ArrayList<>(); 43 | int numFalse = 0; 44 | for (int i = 0; i < 1000; i++) { 45 | boolean element = rnd.nextBoolean(); 46 | if (!element) 47 | numFalse++; 48 | list.add(element); 49 | } 50 | 51 | Collections.sort(list); 52 | 53 | for (int i = 0; i < numFalse; i++) 54 | if (list.get(i)) 55 | throw new RuntimeException("False positive: " + i); 56 | for (int i = numFalse; i < 1000; i++) 57 | if (!list.get(i)) 58 | throw new RuntimeException("False negative: " + i); 59 | return null; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/JavaArrays.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg; 18 | 19 | public class JavaArrays { 20 | 21 | public static void arrayClone() { 22 | byte[] x = new byte[1]; 23 | System.out.println(x.clone().length); 24 | } 25 | 26 | public static void arrayObjectMethods() { 27 | byte[] x = new byte[1]; 28 | x.notify(); 29 | System.out.println(x.clone().length); 30 | } 31 | 32 | public static void arrayObjectMonitors() { 33 | byte[] x = new byte[1]; 34 | synchronized (x) { 35 | System.out.println(x.length); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/Lambdas.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg; 18 | 19 | import java.util.Arrays; 20 | import java.util.Comparator; 21 | import java.util.List; 22 | 23 | public class Lambdas { 24 | 25 | public static Object lambdaTest() { 26 | List l = Arrays.asList(543, 432, 1, -23); 27 | l.sort((integer, t1) -> integer.compareTo(t1)); 28 | return null; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/NullAssumptionAnalysisExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg; 18 | 19 | public class NullAssumptionAnalysisExample { 20 | 21 | public void test1(String a) { 22 | System.out.println("Hello from test1"); 23 | System.out.println(a.length()); 24 | } 25 | 26 | public void test2(Object a) { 27 | System.out.println("Hello from test2"); 28 | System.out.println(a.hashCode()); 29 | String x = (String) a; 30 | System.out.println(x.length()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/StaticInterfaceMethodCall.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg; 18 | 19 | import java.util.function.Function; 20 | 21 | public class StaticInterfaceMethodCall { 22 | public static void callStaticInterfaceMethod() { 23 | Function.identity(); 24 | } 25 | } -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/hierarchies/Creature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.hierarchies; 18 | 19 | public interface Creature { 20 | 21 | void say(String smth); 22 | 23 | default void hello() { 24 | say("Hello"); 25 | } 26 | 27 | interface Animal extends Creature { 28 | } 29 | 30 | interface Fish extends Creature { 31 | @Override 32 | void say(String smth); 33 | } 34 | 35 | interface Dinosaur extends Creature, Animal { 36 | } 37 | 38 | interface Bird extends Creature { 39 | } 40 | 41 | class DinosaurImpl implements Dinosaur { 42 | @Override 43 | public void say(String smth) { 44 | System.out.println("Dino say:" + smth); 45 | } 46 | } 47 | 48 | class TRex extends DinosaurImpl implements Dinosaur { 49 | @Override 50 | public void say(String smth) { 51 | super.say("TRex say:" + smth); 52 | } 53 | 54 | @Override 55 | public void hello() { 56 | // do nothing 57 | } 58 | } 59 | 60 | class Pterodactyl extends DinosaurImpl implements Bird { 61 | @Override 62 | public void say(String smth) { 63 | super.say("Pterodactyl say:" + smth); 64 | } 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/hierarchies/Inheritance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.hierarchies; 18 | 19 | import java.beans.Statement; 20 | 21 | public class Inheritance { 22 | 23 | public static Object test(String[] args) throws Exception { 24 | new Statement(new Private(), "run", null).execute(); 25 | new Statement(new PrivateGeneric(), "run", new Object[] {"generic"}).execute(); 26 | return null; 27 | } 28 | 29 | public static class Public { 30 | public void run() { 31 | throw new Error("method is overridden"); 32 | } 33 | } 34 | 35 | static class Private extends Public { 36 | public void run() { 37 | System.out.println("default"); 38 | } 39 | } 40 | 41 | public static class PublicGeneric { 42 | public void run(T object) { 43 | throw new Error("method is overridden"); 44 | } 45 | } 46 | 47 | static class PrivateGeneric extends PublicGeneric { 48 | public void run(String string) { 49 | System.out.println(string); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/primitives/Primitives.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.primitives; 18 | 19 | public class Primitives { 20 | 21 | public int example(short s, char c) { 22 | return s + c; 23 | } 24 | 25 | public int example(byte s, short c) { 26 | return s + c; 27 | } 28 | 29 | public long example(int s, long c) { 30 | return s + c; 31 | } 32 | 33 | public float example(int s, float c) { 34 | return s + c; 35 | } 36 | 37 | public int example(char s, char c) { 38 | return s + c; 39 | } 40 | 41 | public int unaryExample(char a) { 42 | return -a; 43 | } 44 | 45 | public int unaryExample(byte a) { 46 | return -a; 47 | } 48 | 49 | public int unaryExample(short a) { 50 | return -a; 51 | } 52 | 53 | public long unaryExample(long a) { 54 | return -a; 55 | } 56 | 57 | public float unaryExample(float a) { 58 | return -a; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/structure/EnumExamples.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.structure; 18 | 19 | public class EnumExamples { 20 | public enum SimpleEnum { 21 | SUCCESS, ERROR 22 | } 23 | 24 | public enum EnumWithField { 25 | OK(200), NOT_FOUND(404); 26 | 27 | EnumWithField(int statusCode) { 28 | this.statusCode = statusCode; 29 | } 30 | 31 | final int statusCode; 32 | } 33 | 34 | public enum EnumWithStaticInstance { 35 | C1, C2; 36 | 37 | public static final EnumWithStaticInstance instance = C1; 38 | } 39 | 40 | public static void main(String[] args) { 41 | System.out.println(EnumWithStaticInstance.values().length); 42 | } 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/structure/FieldsAndMethods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.structure; 18 | 19 | import org.jacodb.testing.Common; 20 | 21 | public class FieldsAndMethods { 22 | 23 | public static class Common1Child extends Common.Common1 { 24 | private int privateFieldsAndMethods; 25 | 26 | private boolean publicField; 27 | 28 | private void privateFieldsAndMethods() { 29 | } 30 | 31 | private int accessIntField() { 32 | return ((Common.Common1) this).publicField; 33 | } 34 | 35 | private boolean accessBooleanField() { 36 | return publicField; 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/structure/HiddenFieldSuperClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.structure; 18 | 19 | public class HiddenFieldSuperClass { 20 | public int a, b; 21 | 22 | public static class HiddenFieldSuccClass extends HiddenFieldSuperClass { 23 | public double b; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/types/AAA.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.types; 18 | 19 | public class AAA { 20 | 21 | public class BBB { 22 | 23 | } 24 | 25 | static public class CCC { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/types/Comparables.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.types; 18 | 19 | import org.jetbrains.annotations.NotNull; 20 | 21 | public class Comparables { 22 | 23 | public static class ComparableTest1 implements Comparable { 24 | @Override 25 | public int compareTo(@NotNull ComparableTest1 o) { 26 | return 0; 27 | } 28 | } 29 | 30 | public static class ComparableTest2> implements Comparable { 31 | 32 | @Override 33 | public int compareTo(@NotNull T o) { 34 | return 0; 35 | } 36 | } 37 | 38 | public static class ComparableTest3 extends ComparableTest2 { 39 | 40 | } 41 | 42 | public static class ComparableTest4, W extends Comparable> extends ComparableTest2 { 43 | W stateW; 44 | T stateT; 45 | } 46 | 47 | public static class ComparableTest5 extends ComparableTest4 { 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/types/Generics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.types; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | public class Generics { 23 | 24 | 25 | static class LinkedBase> { 26 | T state; 27 | W stateW; 28 | List stateListW; 29 | 30 | } 31 | 32 | 33 | static class LinkedImpl> extends LinkedBase { 34 | } 35 | 36 | 37 | static class SingleBase { 38 | 39 | private T state; 40 | private ArrayList stateList; 41 | 42 | T run1(T incoming) { 43 | state = incoming; 44 | stateList.add(incoming); 45 | return incoming; 46 | } 47 | 48 | W run2(List incoming) { 49 | state = incoming.get(0); 50 | stateList.addAll(incoming); 51 | return incoming.get(0); 52 | } 53 | 54 | } 55 | 56 | static class SingleImpl extends SingleBase {} 57 | } 58 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/types/MultipleParametrization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.types; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | public class MultipleParametrization { 23 | 24 | public static class SuperTest1, Z extends List> { 25 | T stateT; 26 | W stateW; 27 | Z stateZ; 28 | 29 | T runT(T in) { 30 | return null; 31 | } 32 | 33 | W runW(W in) { 34 | return null; 35 | } 36 | 37 | Z runZ(Z in) { 38 | return null; 39 | } 40 | } 41 | 42 | public static class SuperTest2, Z extends List> extends SuperTest1 { 43 | } 44 | 45 | public static class SuperTest3 extends SuperTest2, ArrayList>> { 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/types/PrimitiveAndArrays.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.types; 18 | 19 | abstract public class PrimitiveAndArrays { 20 | 21 | private int value = 0; 22 | private int[] intArray = new int[1]; 23 | 24 | abstract int[] run(String[] stringArray); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/types/WildcardBounds.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.types; 18 | 19 | import java.util.List; 20 | 21 | public class WildcardBounds { 22 | 23 | public static class DirectBound { 24 | public List field; 25 | } 26 | 27 | public static class WildcardUpperBound { 28 | public List field; 29 | } 30 | 31 | public static class WildcardUpperBoundString extends WildcardUpperBound { 32 | } 33 | 34 | public static class WildcardLowerBoundString extends WildcardLowerBound { 35 | } 36 | 37 | public static class DirectBoundString extends DirectBound { 38 | } 39 | 40 | public static class WildcardLowerBound { 41 | 42 | public List field; 43 | 44 | public List method(List input) { 45 | return null; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/Generics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.usages; 18 | 19 | import java.util.Collection; 20 | import java.util.List; 21 | 22 | public class Generics> { 23 | 24 | private T niceField; 25 | private List niceList; 26 | 27 | public > void merge(Generics generics) { 28 | } 29 | 30 | public > W merge1(Generics generics) { 31 | return null; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/WithInner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.usages; 18 | 19 | import java.util.Collection; 20 | import java.util.List; 21 | 22 | public class WithInner { 23 | 24 | public class Inner { 25 | public void hello() { 26 | System.out.println("hello"); 27 | } 28 | } 29 | 30 | public static class StaticInner { 31 | public void helloStatic() { 32 | System.out.println("hello static"); 33 | } 34 | } 35 | 36 | public void sayHello() { 37 | new Inner().hello(); 38 | new StaticInner().helloStatic(); 39 | new Runnable() { 40 | @Override 41 | public void run() { 42 | System.out.println("hello anonymous"); 43 | } 44 | }.run(); 45 | 46 | } 47 | 48 | public static void main(String[] args) { 49 | new WithInner1>(); 50 | } 51 | } 52 | 53 | 54 | class WithInner1> { 55 | public static void main(String[] args) { 56 | new WithInner1>(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/direct/DirectA.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.usages.direct; 18 | 19 | import com.google.common.collect.Lists; 20 | 21 | public class DirectA { 22 | 23 | public static boolean called; 24 | 25 | private boolean result; 26 | 27 | public static void setCalled() { 28 | called = true; 29 | System.out.println(called); 30 | } 31 | 32 | public void newSmth() { 33 | this.result = Lists.newArrayList().add(1); 34 | System.out.println(result); 35 | called = true; 36 | System.out.println(called); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/fields/FakeFieldA.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.usages.fields; 18 | 19 | 20 | public class FakeFieldA { 21 | 22 | public int a; 23 | public int b; 24 | private final FieldB fieldB = new FieldB(a); 25 | 26 | public FakeFieldA(int a, int b) { 27 | this.a = a; 28 | this.b = b; 29 | } 30 | 31 | public Boolean isPositive() { 32 | System.out.println(b); 33 | return a >= 0; 34 | } 35 | 36 | public void useA(int a) { 37 | System.out.println(b); 38 | this.a = a; 39 | } 40 | 41 | private void useCPrivate(int c) { 42 | System.out.println(a); 43 | fieldB.c = c; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/fields/FieldA.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.usages.fields; 18 | 19 | public class FieldA { 20 | 21 | public int a; 22 | public int b; 23 | private final FieldB fieldB = new FieldB(a); 24 | 25 | public FieldA(int a, int b) { 26 | this.a = a; 27 | this.b = b; 28 | } 29 | 30 | public Boolean isPositive() { 31 | System.out.println(b); 32 | return a >= 0; 33 | } 34 | 35 | public void useA(int a) { 36 | System.out.println(b); 37 | this.a = a; 38 | } 39 | 40 | private void useCPrivate(int c) { 41 | System.out.println(a); 42 | fieldB.c = c; 43 | } 44 | 45 | } 46 | 47 | 48 | class FieldAImpl extends FieldA { 49 | 50 | public final FieldB fieldB = new FieldB(1); 51 | 52 | public FieldAImpl() { 53 | super(1, 1); 54 | } 55 | 56 | void hello() { 57 | System.out.println(a); 58 | } 59 | 60 | void fieldB() { 61 | System.out.println(fieldB); 62 | } 63 | } 64 | 65 | 66 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/fields/FieldB.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.usages.fields; 18 | 19 | public class FieldB { 20 | 21 | int c; 22 | 23 | FieldB(int c) { 24 | this.c = c; 25 | } 26 | 27 | private void useCPrivate() { 28 | c = 10; 29 | } 30 | 31 | private void dumpCPrivate() { 32 | System.out.println(c); 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/methods/MethodA.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.usages.methods; 18 | 19 | public class MethodA { 20 | 21 | public void hello() { 22 | System.out.println("hello"); 23 | } 24 | 25 | public void hello1() { 26 | System.out.println("hello"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/methods/MethodB.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.usages.methods; 18 | 19 | public class MethodB { 20 | 21 | private void hoho() { 22 | new MethodA().hello(); 23 | new MethodC().hello(); 24 | new MethodC().hello1(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/methods/MethodC.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.usages.methods; 18 | 19 | public class MethodC extends MethodA { 20 | 21 | @Override 22 | public void hello() { 23 | super.hello(); 24 | System.out.println("from MethodC"); 25 | } 26 | 27 | @Override 28 | public void hello1() { 29 | System.out.println("from MethodC"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/Enums.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing 18 | 19 | enum class Enums { 20 | SIMPLE, 21 | COMPLEX, 22 | SUPER_COMPLEX; 23 | } 24 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/Foo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing 18 | 19 | import org.junit.jupiter.api.Nested 20 | 21 | @Nested 22 | class Foo { 23 | 24 | var foo: Int = 0 25 | private var bar: String = "" 26 | 27 | fun smthPublic(foo: Int) = foo 28 | 29 | private fun smthPrivate(): Int = foo 30 | } 31 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/Hierarchy.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing 18 | 19 | 20 | interface SuperDuper { 21 | fun say() {} 22 | } 23 | 24 | open class A : SuperDuper 25 | 26 | open class B : A() { 27 | fun saySmth(phrase: String) { 28 | } 29 | } 30 | 31 | open class C() : B() { 32 | 33 | constructor(smth: String) : this() 34 | constructor(smth: String, smth2: String) : this() 35 | 36 | fun saySmth() { 37 | 38 | } 39 | } 40 | 41 | open class D : B() -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/DefaultArgs.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg 18 | 19 | class DefaultArgs { 20 | class A( 21 | val c1: Boolean, 22 | val c2: Boolean, 23 | val c3: Boolean, 24 | val c4: String 25 | ) { 26 | override fun equals(o: Any?): Boolean { 27 | if (o !is A) return false; 28 | return c1 == o.c1 && 29 | c2 == o.c2 && 30 | c3 == o.c3 && 31 | c4 == o.c4 32 | } 33 | } 34 | 35 | fun reformat( 36 | str : String, 37 | normalizeCase : Boolean = true, 38 | uppercaseFirstLetter : Boolean = true, 39 | divideByCamelHumps : Boolean = true, 40 | wordSeparator : String = " " 41 | ) = 42 | A(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator) 43 | 44 | 45 | fun box() : String { 46 | val expected = A(true, true, true, " ") 47 | if(reformat("", true, true) != expected) return "fail" 48 | return "OK" 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/DifferentReceivers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg 18 | 19 | import org.junit.jupiter.api.Assertions.assertEquals 20 | 21 | class DifferentReceivers { 22 | 23 | var log: String = "" 24 | 25 | class MyClass(val value: String) 26 | 27 | inline fun runLogged(entry: String, action: () -> T): T { 28 | log += entry 29 | return action() 30 | } 31 | 32 | operator fun MyClass.provideDelegate(host: Any?, p: Any): String = 33 | runLogged("tdf(${this.value});") { this.value } 34 | 35 | operator fun String.getValue(receiver: Any?, p: Any): String = 36 | runLogged("get($this);") { this } 37 | 38 | val testO by runLogged("O;") { MyClass("O") } 39 | val testK by runLogged("K;") { "K" } 40 | val testOK = runLogged("OK;") { testO + testK } 41 | 42 | fun box(): String { 43 | assertEquals("O;tdf(O);K;OK;get(O);get(K);", log) 44 | return testOK 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/DoubleComparison.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg 18 | 19 | class DoubleComparison { 20 | fun box(): String { 21 | if ((-0.0 as Comparable) >= 0.0) return "fail" 22 | return "OK" 23 | } 24 | } -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/Equals.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg 18 | 19 | class Equals { 20 | 21 | fun equals1(a: Float, b: Float) = a == b 22 | 23 | fun equals2(a: Float?, b: Float?) = a!! == b!! 24 | 25 | fun equals3(a: Float?, b: Float?) = a != null && b != null && a == b 26 | 27 | fun equals4(a: Float?, b: Float?) = if (a is Float && b is Float) a == b else null!! 28 | 29 | fun equals5(a: Any?, b: Any?): Boolean { 30 | return if (a is Float && b is Float) a == b else null!! 31 | } 32 | 33 | fun box(): String { 34 | if (-0.0F != 0.0F) return "fail 0" 35 | if (!equals1(-0.0F, 0.0F)) return "fail 1" 36 | if (!equals2(-0.0F, 0.0F)) return "fail 2" 37 | if (!equals3(-0.0F, 0.0F)) return "fail 3" 38 | if (!equals4(-0.0F, 0.0F)) return "fail 4" 39 | 40 | // Smart casts behavior in 1.2 41 | if (!equals5(-0.0F, 0.0F)) return "fail 5" 42 | 43 | return "OK" 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/InvokeMethodWithException.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg 18 | 19 | class InvokeMethodWithException { 20 | 21 | class A { 22 | fun lol(a: Int): Int { 23 | return 888/a 24 | } 25 | } 26 | 27 | fun box():String { 28 | val method = A::class.java.getMethod("lol", Int::class.java) 29 | var failed = false 30 | try { 31 | method.invoke(null, 0) 32 | } 33 | catch(e: Exception) { 34 | failed = true 35 | } 36 | 37 | return if (!failed) "fail" else "OK" 38 | } 39 | 40 | } 41 | 42 | fun main() { 43 | println(InvokeMethodWithException().box()) 44 | } -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/Overloading.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg 18 | 19 | import kotlin.reflect.KClass 20 | import kotlin.reflect.KFunction0 21 | 22 | class Overloading { 23 | 24 | inline fun test(kFunction: KFunction0, test: T.() -> Unit) { 25 | val annotation = kFunction.annotations.single() as T 26 | annotation.test() 27 | } 28 | 29 | fun check(b: Boolean, message: String) { 30 | if (!b) throw RuntimeException(message) 31 | } 32 | 33 | annotation class Foo(val a: FloatArray = [], val b: Array = [], val c: Array> = []) 34 | 35 | @Foo(a = [1f, 2f, 1 / 0f]) 36 | fun test1() {} 37 | 38 | @Foo(b = ["Hello", ", ", "Kot" + "lin"]) 39 | fun test2() {} 40 | 41 | @Foo(c = [Int::class, Array::class, Foo::class]) 42 | fun test3() {} 43 | 44 | fun box(): String { 45 | test(::test1) { 46 | check(a.contentEquals(floatArrayOf(1f, 2f, Float.POSITIVE_INFINITY)), "Fail 1: ${a.joinToString()}") 47 | } 48 | 49 | test(::test2) { 50 | check(b.contentEquals(arrayOf("Hello", ", ", "Kotlin")), "Fail 2: ${b.joinToString()}") 51 | } 52 | 53 | test(::test3) { 54 | check(c.contentEquals(arrayOf(Int::class, Array::class, Foo::class)), "Fail 3: ${c.joinToString()}") 55 | } 56 | 57 | return "OK" 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/Sequence.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg 18 | 19 | class KotlinSequence { 20 | 21 | val xs = listOf("a", "b", "c", "d") 22 | 23 | fun box(): String { 24 | var s = "" 25 | 26 | for ((i, _) in xs.withIndex()) { 27 | s += "$i;" 28 | } 29 | 30 | return if (s == "0;1;2;3;") "OK" else "fail: '$s'" 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/SimpleTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg 18 | 19 | class SimpleTest { 20 | 21 | fun box(): String { 22 | return "OK" 23 | } 24 | } -------------------------------------------------------------------------------- /jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/Varargs.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.testing.cfg 18 | 19 | import org.junit.jupiter.api.Assertions.assertEquals 20 | 21 | 22 | class Varargs { 23 | 24 | 25 | fun foo(vararg a: T) = a.size 26 | 27 | inline fun bar(block: () -> T): Array { 28 | assertEquals(2, foo(block(), block())) 29 | 30 | return arrayOf(block(), block(), block()) 31 | } 32 | 33 | inline fun empty() = arrayOf() 34 | 35 | fun box(): String { 36 | var i = 0 37 | val a: Array = bar() { i++; i.toString() } 38 | assertEquals("345", a.joinToString("")) 39 | return "OK" 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /jacodb-examples/build.gradle.kts: -------------------------------------------------------------------------------- 1 | dependencies { 2 | api(project(":jacodb-core")) 3 | api(project(":jacodb-api")) 4 | api(project(":jacodb-analysis")) 5 | 6 | implementation(Libs.slf4j_simple) 7 | implementation(Libs.soot_utbot_fork) 8 | implementation(Libs.kotlinx_coroutines_reactor) 9 | } 10 | 11 | tasks.create("runJacoDBPerformanceAnalysis") { 12 | classpath = sourceSets.main.get().runtimeClasspath 13 | mainClass.set("org.jacodb.examples.analysis.PerformanceMetricsKt") 14 | } 15 | 16 | tasks.create("runSootPerformanceAnalysis") { 17 | classpath = sourceSets.main.get().runtimeClasspath 18 | mainClass.set("org.jacodb.examples.analysis.SootPerformanceMetricsKt") 19 | } -------------------------------------------------------------------------------- /jacodb-taint-configuration/README.md: -------------------------------------------------------------------------------- 1 | # Module jacodb-configuration 2 | 3 | A module that contains a format suitable for taint configuration of static analyses. -------------------------------------------------------------------------------- /jacodb-taint-configuration/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java") 3 | kotlin("plugin.serialization") 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | implementation(project(":jacodb-api")) 12 | implementation(project(":jacodb-core")) 13 | implementation(testFixtures(project(":jacodb-core"))) 14 | 15 | implementation(Libs.kotlinx_serialization_core) 16 | implementation(Libs.kotlinx_serialization_json) // for local tests only 17 | 18 | testImplementation(Libs.kotlin_logging) 19 | } 20 | 21 | tasks.test { 22 | useJUnitPlatform() 23 | } -------------------------------------------------------------------------------- /jacodb-taint-configuration/src/main/kotlin/org/jacodb/taint/configuration/TaintConfigurationItem.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.taint.configuration 18 | 19 | import org.jacodb.api.JcMethod 20 | 21 | sealed interface TaintConfigurationItem 22 | 23 | data class TaintEntryPointSource( 24 | val method: JcMethod, 25 | val condition: Condition, 26 | val actionsAfter: List, 27 | ) : TaintConfigurationItem 28 | 29 | data class TaintMethodSource( 30 | val method: JcMethod, 31 | val condition: Condition, 32 | val actionsAfter: List, 33 | ) : TaintConfigurationItem 34 | 35 | data class TaintMethodSink( 36 | val method: JcMethod, 37 | val ruleNote: String, 38 | val cwe: List, 39 | val condition: Condition, 40 | ) : TaintConfigurationItem 41 | 42 | data class TaintPassThrough( 43 | val method: JcMethod, 44 | val condition: Condition, 45 | val actionsAfter: List, 46 | ) : TaintConfigurationItem 47 | 48 | data class TaintCleaner( 49 | val method: JcMethod, 50 | val condition: Condition, 51 | val actionsAfter: List, 52 | ) : TaintConfigurationItem 53 | -------------------------------------------------------------------------------- /jacodb-taint-configuration/src/main/kotlin/org/jacodb/taint/configuration/TaintMark.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.jacodb.taint.configuration 18 | 19 | import kotlinx.serialization.Serializable 20 | 21 | @Serializable 22 | data class TaintMark(val name: String) { 23 | override fun toString(): String = name 24 | 25 | companion object { 26 | val NULLNESS: TaintMark = TaintMark("NULLNESS") 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "***** Check license headers before commit *****" 4 | 5 | if [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then 6 | ./gradlew.bat checkLicense 7 | elif [ "$(expr substr $(uname -s) 1 4)" == "MSYS" ]; then 8 | ./gradlew.bat checkLicense 9 | else 10 | ./gradlew checkLicense 11 | fi 12 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "jacodb" 2 | 3 | plugins { 4 | `gradle-enterprise` 5 | id("org.danilopianini.gradle-pre-commit-git-hooks") version "1.1.11" 6 | } 7 | 8 | gradleEnterprise { 9 | buildScan { 10 | termsOfServiceUrl = "https://gradle.com/terms-of-service" 11 | termsOfServiceAgree = "yes" 12 | } 13 | } 14 | 15 | gitHooks { 16 | preCommit { 17 | from(file("pre-commit")) 18 | } 19 | createHooks(true) 20 | } 21 | 22 | include("jacodb-api") 23 | include("jacodb-core") 24 | include("jacodb-analysis") 25 | include("jacodb-examples") 26 | include("jacodb-benchmarks") 27 | include("jacodb-cli") 28 | include("jacodb-approximations") 29 | include("jacodb-taint-configuration") 30 | --------------------------------------------------------------------------------