Remove kotlin compiler and intellij code warnings
MODIFY
src/test/java/de/fraunhofer/aisec/codyze/crymlin/AbstractMarkTest.kt
src/test/java/de/fraunhofer/aisec/codyze/crymlin/AbstractMarkTest.kt
@@ -5,7 +5,6 @@ import de.fraunhofer.aisec.codyze.analysis.AnalysisServer
import de.fraunhofer.aisec.codyze.analysis.Finding
import de.fraunhofer.aisec.codyze.analysis.ServerConfiguration
import de.fraunhofer.aisec.codyze.analysis.TypestateMode
-import de.fraunhofer.aisec.codyze.analysis.wpds.NFA
import de.fraunhofer.aisec.cpg.TranslationManager
import java.io.*
import java.lang.Exception
@@ -44,7 +43,7 @@ abstract class AbstractMarkTest : AbstractTest() {
var resource = classLoader.getResource(sourceFileName)
assertNotNull(resource, "Resource $sourceFileName not found")
- var javaFile = File(resource!!.file)
+ var javaFile = File(resource.file)
assertNotNull(javaFile, "File $sourceFileName not found")
val toAnalyze = ArrayList<File>()
toAnalyze.add(javaFile)
@@ -166,7 +165,7 @@ abstract class AbstractMarkTest : AbstractTest() {
}
}
- if (!missingFindings.isEmpty()) {
+ if (missingFindings.isNotEmpty()) {
println("Missing findings:")
for (missing in missingFindings) {
println(missing)

MODIFY
src/test/java/de/fraunhofer/aisec/codyze/crymlin/CommandsTest.kt
src/test/java/de/fraunhofer/aisec/codyze/crymlin/CommandsTest.kt
@@ -5,7 +5,6 @@ import de.fraunhofer.aisec.codyze.JythonInterpreter
import de.fraunhofer.aisec.codyze.analysis.AnalysisServer
import de.fraunhofer.aisec.codyze.analysis.ServerConfiguration
import de.fraunhofer.aisec.codyze.analysis.TypestateMode
-import de.fraunhofer.aisec.codyze.analysis.wpds.NFA
import java.io.*
import kotlin.test.assertTrue
import org.junit.jupiter.api.*

MODIFY
src/test/java/de/fraunhofer/aisec/codyze/crymlin/FindingDescriptionTest.kt
src/test/java/de/fraunhofer/aisec/codyze/crymlin/FindingDescriptionTest.kt
@@ -21,7 +21,7 @@ internal class FindingDescriptionTest {
val onFailId = "WrongUseOfBotan_CipherMode"
val regions = listOf(Region(1, 2, 10, 12))
val isProblem = true
- val f = Finding(logMsg, artifactUri, onFailId, regions, isProblem)
+ Finding(logMsg, artifactUri, onFailId, regions, isProblem)
// Initialize database with explanations
val fd = instance

MODIFY
src/test/java/de/fraunhofer/aisec/codyze/crymlin/GithubTest.kt
src/test/java/de/fraunhofer/aisec/codyze/crymlin/GithubTest.kt
@@ -40,9 +40,9 @@ internal class GithubTest : AbstractTest() {
for (f in files) {
ret.add(f.absolutePath.substring(baseFolder!!.length + 1)) // only use the file name
}
- Collections.sort(ret)
+ ret.sort()
// random!
- Collections.shuffle(ret)
+ ret.shuffle()
if (MAX_FILES_TO_SCAN != -1) {
ret = ret.subList(FILES_OFFSET, FILES_OFFSET + MAX_FILES_TO_SCAN)
}
@@ -96,7 +96,7 @@ internal class GithubTest : AbstractTest() {
val tmpString = sourceFileName
val matchingFiles =
dir.listFiles { pathname: File -> pathname.name.endsWith("$tmpString.out") }
- if (!RESCAN && matchingFiles != null && matchingFiles.size > 0) {
+ if (!RESCAN && matchingFiles != null && matchingFiles.isNotEmpty()) {
println("File already scanned")
return
}

MODIFY
src/test/java/de/fraunhofer/aisec/codyze/crymlin/MarkLoadOutputTest.kt
src/test/java/de/fraunhofer/aisec/codyze/crymlin/MarkLoadOutputTest.kt
@@ -22,7 +22,7 @@ internal class MarkLoadOutputTest {
for ((key, markModel) in allModels) {
val reconstructed = StringBuilder()
val entities = ArrayList(markModel.entities)
- if (!entities.isEmpty()) {
+ if (entities.isNotEmpty()) {
// they all have the same packed name in our context
reconstructed.append("package ").append(entities[0].packageName).append("\n")
}
@@ -40,14 +40,14 @@ internal class MarkLoadOutputTest {
var full = String(Files.readAllBytes(Paths.get(key)))
full = full.replace("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)".toRegex(), "")
for (line in full.split("\n").toTypedArray()) {
- if (!line.strip().isEmpty()) {
- sanitizedOriginal.append(line.strip()).append("\n")
+ if (line.trim().isNotEmpty()) {
+ sanitizedOriginal.append(line.trim()).append("\n")
}
}
val sanitizedReconstructed = StringBuilder()
for (line in reconstructed.toString().split("\n").toTypedArray()) {
- if (!line.strip().isEmpty()) {
- sanitizedReconstructed.append(line.strip()).append("\n")
+ if (line.trim().isNotEmpty()) {
+ sanitizedReconstructed.append(line.trim()).append("\n")
}
}
assertEquals(sanitizedOriginal.toString(), sanitizedReconstructed.toString())
@@ -67,7 +67,7 @@ internal class MarkLoadOutputTest {
assertNotNull(markPoC1)
val markModelFiles = markPoC1.parent
val directories =
- File(markModelFiles).list { current: File?, name: String -> name.endsWith(".mark") }
+ File(markModelFiles).list { _: File?, name: String -> name.endsWith(".mark") }
assertNotNull(directories)
val parser = XtextParser()
for (markFile in directories) {

MODIFY
src/test/java/de/fraunhofer/aisec/codyze/crymlin/RealBotanTest.kt
src/test/java/de/fraunhofer/aisec/codyze/crymlin/RealBotanTest.kt
@@ -17,11 +17,11 @@ internal class RealBotanTest : AbstractMarkTest() {
@Throws(Exception::class)
fun testSimple() {
// Just a very simple test to explore the graph
- val findings =
performTest(
"real-examples/botan/streamciphers/bsex.cpp",
"real-examples/botan/streamciphers/bsex.mark"
)
+
val graph = ctx!!.graph
val variables =
graph

MODIFY
src/test/java/de/fraunhofer/aisec/codyze/crymlin/RuleEnsureSemanticsTest.kt
src/test/java/de/fraunhofer/aisec/codyze/crymlin/RuleEnsureSemanticsTest.kt
@@ -7,7 +7,6 @@ import de.fraunhofer.aisec.codyze.analysis.ServerConfiguration
import de.fraunhofer.aisec.codyze.analysis.TypestateMode
import de.fraunhofer.aisec.codyze.analysis.markevaluation.ExpressionEvaluator
import de.fraunhofer.aisec.codyze.analysis.resolution.ConstantValue
-import de.fraunhofer.aisec.codyze.analysis.wpds.NFA
import de.fraunhofer.aisec.codyze.markmodel.MarkModelLoader
import de.fraunhofer.aisec.cpg.ExperimentalGraph
import de.fraunhofer.aisec.cpg.TranslationManager
@@ -102,7 +101,7 @@ internal class RuleEnsureSemanticsTest {
assertNotNull(markFile)
var directoryContent =
- markFile.listFiles { current: File?, name: String -> name.endsWith(".mark") }
+ markFile.listFiles { _: File?, name: String -> name.endsWith(".mark") }
if (directoryContent == null) {
directoryContent = arrayOf(markFile)
}

MODIFY
src/test/java/de/fraunhofer/aisec/codyze/crymlin/TestAppender.kt
src/test/java/de/fraunhofer/aisec/codyze/crymlin/TestAppender.kt
@@ -5,23 +5,25 @@ import org.apache.logging.log4j.Level
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.*
import org.apache.logging.log4j.core.appender.AbstractAppender
+import org.apache.logging.log4j.core.config.Property
import org.apache.logging.log4j.core.config.plugins.Plugin
import org.apache.logging.log4j.core.config.plugins.PluginAttribute
import org.apache.logging.log4j.core.config.plugins.PluginElement
import org.apache.logging.log4j.core.config.plugins.PluginFactory
@Plugin(name = "TestAppender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE)
-class TestAppender(name: String?, filter: Filter?) : AbstractAppender(name, filter, null) {
+class TestAppender(name: String?, filter: Filter?) :
+ AbstractAppender(name, filter, null, true, Property.EMPTY_ARRAY) {
private val events = ArrayList<LogEvent>()
override fun append(event: LogEvent) {
synchronized(events) { events.add(event.toImmutable()) }
}
fun getLog(vararg levels: Level?): List<LogEvent> {
- val levelHashSet = HashSet(Arrays.asList(*levels))
+ val levelHashSet = HashSet(listOf(*levels))
val ret: MutableList<LogEvent> = ArrayList()
for (e in events) {
- if (levels.size == 0 || levelHashSet.contains(e.level)) {
+ if (levels.isEmpty() || levelHashSet.contains(e.level)) {
ret.add(e)
}
}

MODIFY
src/test/java/de/fraunhofer/aisec/codyze/crymlin/WpdsTest.kt
src/test/java/de/fraunhofer/aisec/codyze/crymlin/WpdsTest.kt
@@ -10,8 +10,6 @@ import de.fraunhofer.aisec.mark.markDsl.OrderExpression
import java.io.*
import java.lang.Exception
import java.util.HashSet
-import java.util.function.BinaryOperator
-import java.util.function.Function
import java.util.stream.Collectors
import kotlin.Throws
import kotlin.test.assertEquals
@@ -38,7 +36,7 @@ internal class WpdsTest : AbstractMarkTest() {
edgesFSM.add("START.START -> " + n.name) // artificial node existing in the NFA
}
val seen: MutableSet<StateNode> = HashSet()
- while (!worklist.isEmpty()) {
+ while (worklist.isNotEmpty()) {
val nextWorkList: MutableSet<StateNode> = HashSet()
for (n in worklist) {
for (succ in n.successors) {
@@ -110,14 +108,13 @@ internal class WpdsTest : AbstractMarkTest() {
val findings = performTest("unittests/wpds-vector-example.java", "unittests/vector.mark")
// Extract <line nr, isProblem> from findings
- val startLineNumbers =
findings
.stream()
.collect(
Collectors.toMap(
- Function { f: Finding? -> f!!.regions[0].startLine },
- Function { obj: Finding? -> obj!!.isProblem },
- BinaryOperator { isProblemA: Boolean, isProblemB: Boolean ->
+ { f: Finding? -> f!!.regions[0].startLine },
+ { obj: Finding? -> obj!!.isProblem },
+ { isProblemA: Boolean, isProblemB: Boolean ->
println("Several findings : $isProblemA/$isProblemB")
isProblemA && isProblemB
}
@@ -136,9 +133,9 @@ internal class WpdsTest : AbstractMarkTest() {
.stream()
.collect(
Collectors.toMap(
- Function { f: Finding? -> f!!.regions[0].startLine },
- Function { obj: Finding? -> obj!!.isProblem },
- BinaryOperator { isProblemA: Boolean, isProblemB: Boolean ->
+ { f: Finding? -> f!!.regions[0].startLine },
+ { obj: Finding? -> obj!!.isProblem },
+ { isProblemA: Boolean, isProblemB: Boolean ->
println("Several findings : $isProblemA/$isProblemB")
isProblemA && isProblemB
}
@@ -172,9 +169,9 @@ internal class WpdsTest : AbstractMarkTest() {
.stream()
.collect(
Collectors.toMap(
- Function { f: Finding? -> f!!.regions[0].startLine },
- Function { obj: Finding? -> obj!!.isProblem },
- BinaryOperator { isProblemA: Boolean, isProblemB: Boolean ->
+ { f: Finding? -> f!!.regions[0].startLine },
+ { obj: Finding? -> obj!!.isProblem },
+ { isProblemA: Boolean, isProblemB: Boolean ->
println("Several findings : $isProblemA/$isProblemB")
isProblemA && isProblemB
}
@@ -210,9 +207,9 @@ internal class WpdsTest : AbstractMarkTest() {
.stream()
.collect(
Collectors.toMap(
- Function { f: Finding? -> f!!.regions[0].startLine },
- Function { obj: Finding? -> obj!!.isProblem },
- BinaryOperator { isProblemA: Boolean, isProblemB: Boolean ->
+ { f: Finding? -> f!!.regions[0].startLine },
+ { obj: Finding? -> obj!!.isProblem },
+ { isProblemA: Boolean, isProblemB: Boolean ->
println("Several findings : $isProblemA/$isProblemB")
isProblemA && isProblemB
}
@@ -241,9 +238,9 @@ internal class WpdsTest : AbstractMarkTest() {
.stream()
.collect(
Collectors.toMap(
- Function { f: Finding? -> f!!.regions[0].startLine },
- Function { obj: Finding? -> obj!!.isProblem },
- BinaryOperator { isProblemA: Boolean, isProblemB: Boolean ->
+ { f: Finding? -> f!!.regions[0].startLine },
+ { obj: Finding? -> obj!!.isProblem },
+ { isProblemA: Boolean, isProblemB: Boolean ->
println("Several findings : $isProblemA/$isProblemB")
isProblemA && isProblemB
}
@@ -273,9 +270,9 @@ internal class WpdsTest : AbstractMarkTest() {
.stream()
.collect(
Collectors.toMap(
- Function { f: Finding? -> f!!.regions[0].startLine },
- Function { obj: Finding? -> obj!!.isProblem },
- BinaryOperator { isProblemA: Boolean, isProblemB: Boolean ->
+ { f: Finding? -> f!!.regions[0].startLine },
+ { obj: Finding? -> obj!!.isProblem },
+ { isProblemA: Boolean, isProblemB: Boolean ->
println("Several findings : $isProblemA/$isProblemB")
isProblemA && isProblemB
}
@@ -303,9 +300,9 @@ internal class WpdsTest : AbstractMarkTest() {
.stream()
.collect(
Collectors.toMap(
- Function { f: Finding? -> f!!.regions[0].startLine },
- Function { obj: Finding? -> obj!!.isProblem },
- BinaryOperator { isProblemA: Boolean, isProblemB: Boolean ->
+ { f: Finding? -> f!!.regions[0].startLine },
+ { obj: Finding? -> obj!!.isProblem },
+ { isProblemA: Boolean, isProblemB: Boolean ->
println("Several findings : $isProblemA/$isProblemB")
isProblemA && isProblemB
}
@@ -331,9 +328,9 @@ internal class WpdsTest : AbstractMarkTest() {
.stream()
.collect(
Collectors.toMap(
- Function { f: Finding? -> f!!.regions[0].startLine },
- Function { obj: Finding? -> obj!!.isProblem },
- BinaryOperator { isProblemA: Boolean, isProblemB: Boolean ->
+ { f: Finding? -> f!!.regions[0].startLine },
+ { obj: Finding? -> obj!!.isProblem },
+ { isProblemA: Boolean, isProblemB: Boolean ->
println("Several findings : $isProblemA/$isProblemB")
isProblemA && isProblemB
}
@@ -355,9 +352,9 @@ internal class WpdsTest : AbstractMarkTest() {
.stream()
.collect(
Collectors.toMap(
- Function { f: Finding? -> f!!.regions[0].startLine },
- Function { obj: Finding? -> obj!!.isProblem },
- BinaryOperator { isProblemA: Boolean, isProblemB: Boolean ->
+ { f: Finding? -> f!!.regions[0].startLine },
+ { obj: Finding? -> obj!!.isProblem },
+ { isProblemA: Boolean, isProblemB: Boolean ->
println("Several findings : $isProblemA/$isProblemB")
isProblemA || isProblemB
}
@@ -391,11 +388,11 @@ internal class WpdsTest : AbstractMarkTest() {
.stream()
.collect(
Collectors.toMap(
- Function { f: Finding? ->
+ { f: Finding? ->
if (f!!.regions.isEmpty()) -1 else f.regions[0].startLine
},
- Function { obj: Finding? -> obj!!.isProblem },
- BinaryOperator { isProblemA: Boolean, isProblemB: Boolean ->
+ { obj: Finding? -> obj!!.isProblem },
+ { isProblemA: Boolean, isProblemB: Boolean ->
println("Several findings : $isProblemA/$isProblemB")
isProblemA && isProblemB
}

Remove kotlin compiler and intellij code warnings (#268)

Co-authored-by: Christian Banse <christian.banse@aisec.fraunhofer.de>