cannot access map during function

Answered

For the function `convertToMarkDown` https://github.com/madneal/sec-dog/blob/e63eb04aa9226bcc175d05f849edf6598bd9d233/src/main/kotlin/com/github/madneal/secdog/Checker.kt#L53

I tried to add a map save the `ad.titlle` which was a String like this.

fun convertToMarkDown(ads: List<Advisory>, packageName: String): String {
var result = StringBuilder().append("# $packageName\n")
var map = mutableMapOf<String, Boolean>()
for (ad in ads) {
map.put(ad.title, true)
println(map)
val aliases = ad.aliases.joinToString(",")
val refs = ad.referenceURLs.map { it -> "* $it " }.joinToString("\n")
var adString = """

The `println(map)` would print nothing. And if I debug the fuction, the map would not be accessed.

I tried to write a demo function

https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS42LjIxIiwicGxhdGZvcm0iOiJqYXZhIiwiYXJncyI6IiIsIm5vbmVNYXJrZXJzIjp0cnVlLCJ0aGVtZSI6ImlkZWEiLCJjb2RlIjoiLyoqXG4gKiBZb3UgY2FuIGVkaXQsIHJ1biwgYW5kIHNoYXJlIHRoaXMgY29kZS5cbiAqIHBsYXkua290bGlubGFuZy5vcmdcbiAqL1xuXG5mdW4gbWFpbigpIHtcbiAgICBwcmludGxuKFwiSGVsbG8sIHdvcmxkISEhXCIpXG4gICAgXG4gICAgdGVzdEZvck1hcCgpXG59XG5cbmZ1biB0ZXN0Rm9yTWFwKCkge1xuICAgICAgICB2YXIgbGlzdCA9IG11dGFibGVMaXN0T2YoXCJhYWFcIiwgXCJiYmJcIiwgXCJjY2NjXCIpXG4gICAgICAgIHZhciBtYXAgPSBtdXRhYmxlTWFwT2Y8U3RyaW5nLCBCb29sZWFuPigpXG4gICAgICAgIGZvciAoZWxlIGluIGxpc3QpIHtcbiAgICAgICAgICAgIG1hcC5wdXQoZWxlLCB0cnVlKVxuICAgICAgICAgICAgcHJpbnRsbihtYXApXG4gICAgICAgIH1cbiAgICB9XG5cbiJ9

 

 

 

I have no idea why map operation does not work during the function inside the plugin.

0
8 comments

Hi,

Sorry, but the problem is unclear. At the first glance, it seems that the source and executed code are out of sync.

Please try to recompile your project and debug it again. If the issue still happens, prepare a branch with this code and a test project we can use to investigate it. Make sure, that projects do not require any additional setup steps, so we can check it out and run without any additional actions.

0

I have created a `map` branch for test https://github.com/madneal/sec-dog/blob/be23566e4f90f9021c7246dde1099823288ce344/src/test/kotlin/com/github/madneal/secdog/MyPluginTest.kt#L32

The weired is no matter what parameter I pass to the `packageName` parameter of `chcker.Check` method. Inside the method, the parameter seem to always be the parameter I passed fitst time. I am not sure if some cache or something broken. I try to invalidate cache, but doesn't work.

0

I'm sorry, but the tests cannot be run due to the following error:

java.lang.ExceptionInInitializerError
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at junit.framework.TestSuite.createTest(TestSuite.java:60)
    at junit.framework.TestSuite.addTestMethod(TestSuite.java:307)
    at junit.framework.TestSuite.addTestsFromTestCase(TestSuite.java:150)
    at junit.framework.TestSuite.<init>(TestSuite.java:129)
    at org.junit.internal.runners.JUnit38ClassRunner.<init>(JUnit38ClassRunner.java:74)
    at org.junit.internal.builders.JUnit3Builder.runnerForClass(JUnit3Builder.java:11)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:78)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
    at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at jdk.proxy1/jdk.proxy1.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
    at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
    at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
    at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
    at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
    at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private static java.util.LinkedHashSet java.io.DeleteOnExitHook.files accessible: module java.base does not "opens java.io" to unnamed module @4e0ae11f
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
    at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
    at com.intellij.util.ReflectionUtil.findFieldInHierarchy(ReflectionUtil.java:153)
    at com.intellij.util.ReflectionUtil.findAssignableField(ReflectionUtil.java:141)
    at com.intellij.util.ReflectionUtil.getStaticFieldValue(ReflectionUtil.java:338)
    at com.intellij.testFramework.UsefulTestCase.<clinit>(UsefulTestCase.java:352)
    ... 38 more
0

em. There is nothing special configure. The project is created by the https://github.com/JetBrains/intellij-platform-plugin-template. 

I am not sure if there is need to `Run Plugin` and `Run Verification` task.

Gradle JVM

0

I've changed Gradle JVM and it works, sorry.

Also, the plugin works as expected:

 

I don't know what can be the issue cause. Try to check out the project again from scratch.

0

It's so weired. I clone the project from the scratch and delete the `.idea` folder. But I find the problem still exists. Could you try to modify the `packageName` parameter to see if it changed inside the function `Check`.

0

There is an issue in Gradle IntelliJ Plugin 1.5.3. It will be fixed in the next release.

Please use the "clean" task to force recompilation.

0

Please sign in to leave a comment.