ScalaFx MouseEvent: java.lang.NoSuchFieldError: BACK - scalafx

What can be the reason for getting this error in run-time (see title) while referring to ScalaFx class, instead if I switch to JavaFx class reference (workaround) things work as expected? With Scala 2.12 and ScalaFx 8.0.192-R14 things were working without JavaFx based workaround. About the environment: Scala 2.13.1, ScalaFx 12.0.2-R18, IntelliJ 2019.3.2, Java 8, Windows 10. Below I am providing the core snippets hopefully able to highlight the issue.
With ScalaFx MouseEvent class reference it seems to generate the exception with me.button:
import scalafx.Includes._
import scalafx.scene.input.{MouseButton, MouseEvent}
...
def flowPaneEvents(flowpane: FlowPane): Unit = {
flowpane.onMouseClicked = (me: MouseEvent) => {
// this statement causes the exception with scalafx
me.button match {
case MouseButton.Primary => println("primary button")
case MouseButton.Secondary => println("secondary button")
case _ =>
}
me.consume()
}
}
Whereas referring to javaFx classes things are working fine. See below:
import scalafx.Includes._
import javafx.scene.{input => jfxsi}
...
def flowPaneEvents(flowpane: FlowPane): Unit = {
flowpane.onMouseClicked = (me: MouseEvent) => {
// this javafx based reference gets things done
me.getButton match {
case jfxsi.MouseButton.PRIMARY => println("primary button")
case jfxsi.MouseButton.SECONDARY => println("secondary button")
case _ =>
}
me.consume()
}
}
What am I missing (I've tried to re-import sbt library-dependencies, but I've not been lucky so far)?

ScalaFX 12.0.2 is to be used with JavaFX 12. If you are using it with Java 8 you will run into strange issues when you have JavaFX 8 is in the path. Use ScalaFX 8 for Java 8. This is clearly stated on the project website: https://github.com/scalafx/scalafx#scalafx-8
Field "BACK" was added in JavaFX 12. See API documentation here:
https://openjfx.io/javadoc/12/javafx.graphics/javafx/scene/input/MouseButton.html#BACK
It is not present in JavaFX 8, so that is the reason for "java.lang.NoSuchFieldError: BACK" - ScalaFX is trying to access field that is not present.

Related

Gradle Build Failure: Couldn't find outer class

When trying to build, I get this stacktrace:
Exception in thread "main" java.lang.NullPointerException: Couldn't find outer class com/xxx/CheckListPresenter$onAttached$1$5 of com/xxx/CheckListPresenter$onAttached$1$5$1
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:1079)
at com.google.devtools.build.android.desugar.ClassVsInterface.isOuterInterface(ClassVsInterface.java:56)
at com.google.devtools.build.android.desugar.InterfaceDesugaring.visitOuterClass(InterfaceDesugaring.java:246)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:638)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:477)
at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:361)
at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:314)
at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:711)
I checked the CheckListPresenter class and there doesn't appear to have any issues. I tried deleting the class just to see if it would build, but the error just moved on to another class stating the same issue.
The last time I touched this code was a good few months ago, so I am not sure what triggered the change.
Things that may matter: This is an Android project. This is written in Kotlin. This fails on the transformClassesWithDesugarForDebug gradle task
Edits
These are all just stabs in the dark I tried:
Creating a new project and moving in only my source code and gradle files.
Dropping from java 8 to 7.
Different version of JDK. I have tried 1.8.0_151 and 1.8.0_152.
Adding javaMaxHeapSize "4g" to build.gradle.
Upgrading everything: gradle wrapper and every dependency.
Removed Dagger in favor of Koin
Removed Kapt
Used both Preview and Stable releases of Android Studio
Here is my build scan for what good it will do
New discovery:
This is the snippet of code that is killing me:
view?.let { v ->
v.getCancelClicks()
.doOnSubscribe({ disposables.add(it) })
.subscribe({
v.showExitDialog()
.filter { it }
.subscribe({
cancel()
}, this::onError)
}, this::onError)
}
What is strange, is neither one of these alone will give me issues
view?.let { v ->
v.getCancelClicks()
.doOnSubscribe({ disposables.add(it) })
.subscribe({
//removed
}, this::onError)
}
}
or
view?.let { v ->
v.showExitDialog()
.filter { it }
.subscribe({
cancel()
}, this::onError)
}
But together they are a problem.
Something else of note, view is defined in the base class and is a generic.
Currently, my work around is to remove view?.let{ and just use view!!. This is obviously a bug, but I am not sure who to report it to. Gradle, Kotlin, JetBrains, God?
The problem resolved itself when I added android.enableD8.desugaring = true to gradle.properties
I have a way to work around this error: java.lang.NullPointerException: Couldn't find outer class com/iconfitness/iconaudit/common/fragments/SettingsFragment$onCreate$1$1 of com/iconfitness/iconaudit/common/fragments/SettingsFragment$onCreate$1$1$1.
Just move this block code
v.showExitDialog()
.filter { it }
.subscribe({
cancel()
oo other method. I don't meet this problem anymore. I hope this will help you.
The issue is filed here https://issuetracker.google.com/issues/72750890.
Both solutions mentioned there worked for me:
adding classpath 'com.android.tools.build:gradle:3.0.1' to build.gradle or adding android.enableD8.desugaring=true to gradle.properties
As a workaround you can substitute let by null checking. At least code started to compile after this
if (view!=null)
view.showExitDialog()
.filter { it }
.subscribe({
cancel()
}, this::onError)
}

Getting Webpack 2 to support IE8

I want to use Webpack 2 in a large project which must still support IE8.
I've installed babel-preset-env so I can easily deprecate any IE < 11 in future, one by one, once each of the browsers becomes unsupported by this project.
According to the babel-preset-env readme "If you are targeting IE 8 and Chrome 55 [babel-preset-env] will include all plugins required by IE 8 since you would need to support both still."
As I understand it, I also need to install babel-polyfill mostly for its IE5 shim, but also for its polyfills for ES6 and 7 features that I may wish to use.
However having installed these things, my code still falls over on IE8 (in Browserstack) at the point where Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); is first run. A function I thought was getting 'fixed' by the shims.
Is it not getting shimmed properly? Have I missed out a step?
I had the same problem before and here is what I did to solve.
In es6 features,
a class can define a property with get and set to encapsulate a field.
but it is not woroking on IE8.
because the defineProperty method is not supported see the docs,
so we changed the whole code pattern to like below
let val1;
class className {
methodName() {
this.val2 = 'test';
//code here
}
getVal1() {
return val1;
}
setVal1(_val1) {
val1 = _val1;
}
getVal2() {
return this.val2;
}
setVal2(_val2) {
this.val2 = _val2;
}
}
module.exports = className;
and I recommend that adding 'es3ify' see the link,github es3ify to your webpack build for IE7/8

GKComponentSystem in Xcode 8 Swift 3

I'm having trouble converting my project to Swift 3. In previous version of Swift I can declare a class under GKComponentSystem like:
class EnemyMoveComponentSystem: GKComponentSystem {
}
However in swift 3 it forces me to add < GKComponent > in the end as:
class EnemyMoveComponentSystem: GKComponentSystem <GKComponent> {
func updateWithDeltaTime(seconds: TimeInterval, gameScene: GameScene) {
for component in components {
print("something")
}
}
}
But it seems that I can't access each individual component within the system like before
for component in components {
print("something")
}
The line print("something") was never triggered.
How can I fix this?
Any help is appreciated!
Found out what the problem was. I forgot to link the entity to the component system.
.addComponent(foundIn: Entity)

Java debugger can't call some default method implementations

I'm coding in IntelliJ IDEA. When debugging my application, I can't use some default method implementations in Watches.
Here is a condensed example:
public class Friendship {
interface Friend {
default void sayHiTo(Friend friend) {
System.out.println("Hi, " + friend.hashCode());
}
default int amountOfHands() {
return 2;
}
}
public static class BasicFriend implements Friend {
int numberOfFaces() {
return 1;
}
}
public static void main(String[] args) {
System.out.println("Put a breakpoint here");
}
}
In main() method I put a breakpoint and set up three watches:
// Default interface method with dependency
new BasicFriend().sayHiTo(new BasicFriend())
// Default interface method without dependency
new BasicFriend().amountOfHands()
// Class method
new BasicFriend().numberOfFaces()
The first watch throws NoSuchMethodException complaining that method Friendship$BasicFriend.sayHiTo() doesn't exist.
The second watch runs successfully, but strangely it reports a boxed object
{java.lang.Integer#537} "2" instead of just a primitive 2.
The third watch reports a primitive 1, just as expected.
Why is the first watch not working? Is this a bug? Is this actually IDE related? Is it because of some conceptual flaw of default methods? Should it be working as I want it to in the first place? Is the strange result of the second watch somehow related to the issue in the first watch?
Prior to JDK 8u40, default and static interface methods were not supported by JDI (Java Debugger Interface), JDWP (Java Debugger Wire Protocol) and JDB (the standard Java debugger). This is bug JDK-8042123, which is recorded as fixed in 8u40 and a corresponding blurb appears in the 8u40 release notes.
Update to 8u40 or later to fix this issue, at least on the JDK side.
From the bug description, it looks like debugger-side changes are also required, to avoid casting com.sun.jdi.InterfaceType objects to com.sun.jdi.ClassType, but instead call InterfaceType.invokeMethod() directly.
In the specific case of IntelliJ, Suseika confirmed in a comment that 14.1.2 has mostly fixed the issue (except the unexpected boxing), though Mike Kobit still experiences this problem on that version with a ClassCastException suggestive of the incorrect cast above.

Using Firefox for Play Framework integration tests

I've started a new Play application
play new todolist
I created project/Build.scala
import sbt._
import Keys._
object ApplicationBuild extends Build {
val appName = "Your application"
val appVersion = "1.0"
val appDependencies = Seq(
"org.seleniumhq.selenium" % "selenium-firefox-driver" % "2.40.0" % "test"
)
}
I also modified test/IntegrationSpec.scala to use Firefox
#RunWith(classOf[JUnitRunner])
class IntegrationSpec extends Specification {
"Application" should {
"work from within a browser" in {
running(TestServer(9000, application = FakeApplication()), FIREFOX) { browser =>
browser.goTo("http://localhost:9000")
browser.pageSource must contain("Your new application is ready.")
}
}
}
}
When I run play test, a Firefox browser starts, but it never goes to a url. The interesting parts from the exception are
JavaScript error: chrome://browser/content/urlbarBindings.xml, line 648: aUrl is undefined
and
[error] WebDriverException: Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7057; process output follows:
I've put a gist here with the full stacktrace.
What am I doing wrong? How do I get Firefox to work with Play Framework and actually run a test?
If you still having the problem, I had a similar one and solved it updating the selenium dependency:
libraryDependencies ++= Seq("org.seleniumhq.selenium" % "selenium-java" % "2.43.0")
Hope it helps.

Resources