Categories
discuss

Why is HashCode zero for HashMap containing values that are same as keys

I noticed that in Java, hashCode for HashMap that only contain entries where key and values are same, eg {1:1}, {"abc":"abc"} etc. is always zero. Is there any reasoning behind this odd behavior?

Answer

This is a consequence of the specification of the hashCode() for Map.Entry, which requires the hash codes of the keys and values to be xor’d.

The only people who could tell you why that hash code was chosen are the people who wrote it originally, though my impression is that Java regrets specifying this (bad) hash function.

Categories
discuss

Maven+JDK9 modules: Failed to parse module-info

Using 9-ea+171, Maven 3.5.0

I am compiling a project with this module-info.java:

module org.project {
}

But it fails with a mysterious error:

[ERROR] Failed to parse module-info:
[ERROR] With qdox: null
(...)
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile (default-testCompile) on project rli-stubs: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile failed: Failed to parse module-info -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile (default-testCompile) on project rli-stubs: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile failed: Failed to parse module-info
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:563)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile failed: Failed to parse module-info
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
Caused by: java.lang.RuntimeException: Failed to parse module-info
at org.apache.maven.plugin.compiler.TestCompilerMojo.preparePaths(TestCompilerMojo.java:322)
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:742)
at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:170)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more

I recreated the simplest form of the project here: https://github.com/benji/jdk9-mvn5-withqdoxnull

It seems to have something to do with src/test/java/ . If I remove that folder then the build passes.

Answer

You need to put module-info.java to src/main/java. Now it is located in src/main/java/com/test which is wrong. module-info.java must be a top level file.

Categories
discuss

Change text color in mapbox cluster map

I am trying to change the text color in the mapbox cluster map (https://www.mapbox.com/mapbox-gl-js/example/cluster/), but I can’t figure out how.

Here is the relevant code piece:

map.addLayer({
    id: "cluster-count",
    type: "symbol",
    source: "grundbuch",
    filter: ["has", "point_count"],
    layout: {
        "text-field": "{point_count_abbreviated}",
        "text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"],
        "text-size": 12
    }
});

Does anybody know how to do this? I would like to change the number labels to white.

Answer

To change the text color in a map layer you need the "paint" property to set the text-color property REF:

paint: {
  "text-color": "#ffffff"
}

Example

map.addLayer({
  id: "cluster-count",
  type: "symbol",
  source: "grundbuch",
  filter: ["has", "point_count"],
  layout: {
    "text-field": "{point_count_abbreviated}",
    "text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"],
    "text-size": 12
  },
  paint: {
    "text-color": "#ffffff"
  }
});
Categories
discuss

Project won’t build with Kotlin 1.1.3

I have an Android project that I’ve recently updated with 1.1.3, and every time I build I get the following error:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> kotlin.jvm.internal.FunctionReference.<init>(ILjava/lang/Object;)V

Other questions typically say that it means that the stdlib is not included, but I have definitely added it. Using 1.1.2-5 works though, and 1.1.3 has worked for other projects.

Solution

The issue was with me mixing the annotation processor with kapt. For projects like DbFlow and Glide, the annotationProcessor dependency can be directly used with kapt.

Back to the original question:

Here is my Travis log and below are my dependencies:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.3-alpha', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'

    compile("ca.allanwang:kau:${KAU}")

    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:${KOTLIN}"
    testCompile "org.jetbrains.kotlin:kotlin-test-junit:${KOTLIN}"

    debugCompile "com.squareup.leakcanary:leakcanary-android:${LEAK_CANARY}"
    releaseTestCompile "com.squareup.leakcanary:leakcanary-android-no-op:${LEAK_CANARY}"
    releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:${LEAK_CANARY}"
    testCompile "com.squareup.leakcanary:leakcanary-android-no-op:${LEAK_CANARY}"

    compile "com.github.Raizlabs.DBFlow:dbflow:${DBFLOW}"
    compile "com.github.Raizlabs.DBFlow:dbflow-core:${DBFLOW}"
    annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${DBFLOW}"
    kapt "com.github.Raizlabs.DBFlow:dbflow-processor:${DBFLOW}"
    compile "com.github.Raizlabs.DBFlow:dbflow-kotlinextensions:${DBFLOW}"

    //Icons
    compile "com.mikepenz:material-design-iconic-typeface:${IICON_MATERIAL}@aar"
    compile "com.mikepenz:community-material-typeface:${IICON_COMMUNITY}@aar"

    compile "org.jsoup:jsoup:${JSOUP}"

    compile "com.github.bumptech.glide:glide:${GLIDE}"
    annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE}"

    compile("com.mikepenz:materialdrawer:${MATERIAL_DRAWER}@aar") {
        transitive = true
    }
    compile "co.zsmb:materialdrawer-kt:${MATERIAL_DRAWER_KT}"

    compile "nz.bradcampbell:paperparcel:${PAPER_PARCEL}"
    compile "nz.bradcampbell:paperparcel-kotlin:${PAPER_PARCEL}"
    kapt "nz.bradcampbell:paperparcel-compiler:${PAPER_PARCEL}"

    compile "com.jude:swipebackhelper:${SWIPE_BACK}"

    compile("com.crashlytics.sdk.android:crashlytics:${CRASHLYTICS}@aar") {
        transitive = true;
    }
}

Here is the error output when I try building with a full stacktrace: [Removed because this post was too long] I’m not sure if it helps, but dbflow typically has the warning each build since it does not need to generate the classes every time. I’ve sent a question to their repo but I don’t think that is the issue since it works fine with 1.1.2-5

Edit 2: I had a look at ./gradlew dependencies and all of them showed kotlin 1.1.3 (too long to post here). There were some that depended on 1.1.0 from their github sources, but that shouldn’t be affected and excluding those std-libs did not resolve the error.

Edit 3: Upon trying .gradlew app:dependencies | grep org.jetbrains.kotlin I get the following:

$ ./gradlew app:dependencies | grep org.jetbrains.kotlin
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    --- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    --- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         --- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)

Answer

In my experience, you:

  1. Should not mix kapt and annotationProcessor
  2. Use kapt3, by using apply plugin: 'kotlin-kapt'
  3. Do not use kapt { generateStubs true } } (it’s not allowed with kapt3)

Also check whether your Kotlin plugin and your Gradle plugin are up to date.
Additionally I usually don’t use the jre7 version of the standard lib, but I doubt that this is the issue here.

Here is a more exhaustive list of “something with Kotlin doesn’t work”: https://gist.github.com/lmller/3c43eff454f7508474210fb2491b488a

Categories
discuss

Is it possible to execute the OnClick javascript function via selenium webdriver without the click

I am building a new test case and have ran into a new issue I am not sure how to get around. I need to click on an element that is both visiblity: hidden and display: none or at least need a way to execute the javascript function it calls. In the passed I have been able to use IJavascriptExecutor to change an elements visibility or display but this option is no good for this test case as I am dealing with an array of elements that I locate at runtime using `Driver.FindElements’ so I cannot get the exact selector to use my old method for changing display.

IJavaScriptExecutor js = (IJavaScriptExecutor)Driver;
var script = String.Format("document.querySelector('{0}').style.display='inline-block';", selector);
js.ExecuteScript(script);

Attached is a screenshot of the html and the css attributes for the element in question.

The way I see it I have two options I can make this test not dynamic and exercise the functionality on a single hardcoded element (yuck!), or I can figure out how to do this dynamically. So my hope (probably a fools hope) is that I can somehow call the onClick event bound to this button without actually clicking on it. enter image description here

Answer

You could extract the onclick attribute and send it as parameter. You also don’t need to use IJavaScriptExecutor, IWebDriver extends this interface so you can just call ExecuteJavaScript method

IWebElement buttonToClick;
string script = buttonToClick.GetAttribute("onclick");
driver.ExecuteJavaScript<object>(script);

You can also try clicking it with JavaScript

driver.ExecuteJavaScript<object>("arguments[0].click();", buttonToClick);
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..