FS#62704 - [arduino] IDE cannot show serial output due to NoSuchMethodError ByteBuffer.flip

Attached to Project: Community Packages
Opened by Robbert Gurdeep Singh (beardhatcode) - Wednesday, 22 May 2019, 10:06 GMT
Last edited by NicoHood (NicoHood) - Thursday, 13 May 2021, 09:17 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To NicoHood (NicoHood)
Architecture x86_64
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 7
Private No

Details

Description:
Arduino IDE cannot show serial output due to java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;


Additional info:
* package version(s): arduino-1:1.8.9-3 (works in arduino-1:1.8.9-1)
* board: esp8266 (I don't have other boards to test)

Steps to reproduce:

1. Open arduino IDE,
2. Open the attached file (simpleSerial.c)
3. Open the serial monitor
4. Compile and flash
5. The log window shows:

Exception in thread "EventThread /dev/ttyUSB0" java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;
at processing.app.Serial.serialEvent(Serial.java:185)
at jssc.SerialPort$LinuxEventThread.run(SerialPort.java:1299)
This task depends upon

Closed by  NicoHood (NicoHood)
Thursday, 13 May 2021, 09:17 GMT
Reason for closing:  Fixed
Additional comments about closing:  Force java 8 with 1.8.14-1
Comment by Stephen Beck (stephen.beck) - Thursday, 23 May 2019, 15:26 GMT
downloading arduino-1.8.9-linux64.tar.xz from the arduino site and installing with included scrips resolved. had to delete ~/.arduino and scripts did complain, but it works.
Comment by Jonas (joott) - Monday, 27 May 2019, 18:18 GMT
I had the same problem, it's not specific to the esp8266.
Downgrading solved it:
pacman -U /var/cache/pacman/pkg/arduino-1\:1.8.9-1-x86_64.pkg.tar.xz
Comment by Giovanni (ksniffer) - Tuesday, 28 May 2019, 13:38 GMT
Same problem here: arduino 1:1.8.9-3

Cannot be fixed in arduino 1:1.8.9-4?
Comment by Giovanni (ksniffer) - Tuesday, 28 May 2019, 14:54 GMT
Same problem here: arduino 1:1.8.9-3

Cannot be fixed in arduino 1:1.8.9-4?
Comment by Lawrence Glaister (ve7it) - Wednesday, 29 May 2019, 21:13 GMT
Can confirm problem. Was fixed by downgrading to previous version. Sketch does not
matter... just by opening the tools/serial monitor will cause the issue.
last known working version:
sudo pacman -U /var/cache/pacman/pkg/arduino-1:1.8.9-2-x86_64.pkg.tar.xz

I have the following java related packages installed:
jre8-openjdk 8.u212-1
jre8-openjdk-headless 8.u212-1

tried installing (jre-openjdk and jre-openjdk-headless to get latest versions)
jre-openjdk 11.0.3.u4-1
jre-openjdk-headless 11.0.3.u4-1

even after a restart, the exception still exists when opening the serial monitor window.

SUCCESS!
had to remove jre8-openjdk and jre8-openjdk-headless and install the latest
jre-openjdk and jre-openjdk-headless packages. This updated to version 11 of jdk
and the serial monitor is now running without complaints.
Comment by sekret (sekret) - Thursday, 30 May 2019, 18:07 GMT
Uninstalling jre8-openjdk and jre8-openjdk-headless isn't an option for me, because other software depends on it. So for me this issue isn't fixed.
Comment by Alexandria (alexandria) - Monday, 03 June 2019, 05:19 GMT
@sekret

It should be noted that you can switch between multiple Java versions without uninstalling the old version. That's what the `archlinux-java` utility is for. If I'm not mistaken, what it actually does is change the `/usr/lib/jvm/default-runtime` symlink to point to one of the various Java installations. All packages that are for the various runtime versions should show up under `pacman -Ss jre` -- you can install as many different versions as you want. The wiki goes into more detail on this: https://wiki.archlinux.org/index.php/Java#Switching_between_JVM

If whatever you're using requires that jre8 to be default runtime, here is a workaround:

If you look in `/usr/bin/arduino` you'll find a wrapper shell script that is hardcoded to set the default directory. If you copy that wrapper to `/usr/local/bin/arduino` and then edit it, you should be able to override the PATH set in the wrapper to the desired runtime -- thus making Arduino use one Java version while the rest of the system uses another.

It's kind of an ugly approach, but it's all I could think of off the top of my head. If anyone knows anything better let me know. (Also, if this really is the best way, maybe someone should open an issue with the packager for the `arduino` package -- ask them to create a wrapper script that allows you to set this via environment variables.
Comment by Alexandria (alexandria) - Monday, 03 June 2019, 05:53 GMT
On a side note, when I use JRE11 with the Arduino IDE, it gives my compilation console a grey background (despite it still being white-on-black text) and seems to break quite a lot of other parts of the GUI (such as the boarders of check boxes missing). Is this a bug or just some really badly designed theme? Anyone know a fix? (Am using pretty standard Xorg & XFCE4 setup with Intel graphics card, BTW.)

Edit: I tried using JRE10, and it fixed the GUI -- and fixed the error message too. Interesting.
Comment by Wink Saville (winksaville) - Wednesday, 12 June 2019, 20:23 GMT
I'd like to suggest changing depends from java-runtime>=8:

depends=('gtk2' 'desktop-file-utils' 'shared-mime-info' 'java-runtime>=8' 'arduino-builder')

to java-runtime>=10

depends=('gtk2' 'desktop-file-utils' 'shared-mime-info' 'java-runtime>=10' 'arduino-builder')
Comment by Wink Saville (winksaville) - Thursday, 13 June 2019, 22:26 GMT
On a post to the Arduino forum, https://forum.arduino.cc/index.php?topic=621098.msg4208185#msg4208185, I got pointed to the corresponding bug in Arduino on github, https://github.com/arduino/Arduino/issues/8903, and dug a little deeper. Instead of using the system installed version of Java 10 or 11 as I suggested above, https://bugs.archlinux.org/task/62704#comment179725. I now think it would be better to use the Java shipped with released version of arduino was suggested on the github issue, https://github.com/arduino/Arduino/issues/8903#issuecomment-497702534.

The reason is that even though using java 10 or 11 resolves this particular issue I get warnings when I use them:

$ archlinux-java status
Available Java environments:
java-10-openjdk (default)
java-11-openjdk
java-8-openjdk

$ /usr/share/arduino/arduino
Picked up JAVA_TOOL_OPTIONS:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by processing.app.linux.GTKLookAndFeelFixer (file:/usr/share/arduino/lib/arduino-core.jar) to field com.sun.java.swing.plaf.gtk.GTKLookAndFeel.styleFactory
WARNING: Please consider reporting this to the maintainers of processing.app.linux.GTKLookAndFeelFixer
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

This doesn't happen when using the Java 8 shipped with arduino-1.8.9:

$ /home/wink/bin/arduino-1.8.9/java/bin/java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

Which you can see is different from Arch Linux Java 8:

$ archlinux-java status
Available Java environments:
java-10-openjdk
java-11-openjdk
java-8-openjdk (default)

$ /usr/bin/java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-b01)
OpenJDK 64-Bit Server VM (build 25.212-b01, mixed mode)
Comment by G R (gururise) - Monday, 24 June 2019, 19:34 GMT
If what Wink says is accurate, I don't think removing Java 8 and upgrading to Java 10 is the correct fix. The package should probably use the shipped Java version that comes with arduino.

Also the package arduino-1:1.8.9-2-x86_64.pkg.tar.xz works fine on my machine, while arduino-1:1.8.9-3-x86_64.pkg.tar.xz has the problem with the serial monitor. Perhaps identify what changed between the two packages.
Comment by B.M. Horn (bgth) - Wednesday, 17 July 2019, 11:46 GMT
I can confirm the statement of Wink. I also get those warnings if I switch to the newer java version.
Comment by George Farris (horga83) - Thursday, 13 February 2020, 22:55 GMT
Any word on a fix for this bug? As of Arduino-1.8.12 it is still apparent.
Arduino-1.8.9-2 works but nothing higher.

Exception in thread "EventThread /dev/ttyUSB0" java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;
is still the error displayed when trying to use the serial monitor.

Comment by Richard (archer666) - Thursday, 07 May 2020, 10:50 GMT
Same problem here (arduino 1.8.12)

$ java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

Not present with Nano & old bootloader, but present with (new) bootloader
Comment by adam spontarelli (smed) - Tuesday, 12 May 2020, 16:29 GMT
This appears to be fixed upstream as of yesterday. https://github.com/arduino/Arduino/issues/10187
Comment by NicoHood (NicoHood) - Saturday, 11 July 2020, 09:42 GMT
A new arduino version was released. For me it seems to work with java14, can anyone please verify?
Comment by Florian Kraupa (Flo Grauper) - Wednesday, 02 September 2020, 17:40 GMT
Cant confirm that. Problem occurs with arduino 1:1.8.13-2 and jre-openjdk 14.0.2.u12-1
Comment by Julien Deswaef (xuv) - Sunday, 20 September 2020, 10:04 GMT
Confirming this bug seems solved to me on

openjdk version "14.0.2" 2020-07-14
OpenJDK Runtime Environment (build 14.0.2+12)
OpenJDK 64-Bit Server VM (build 14.0.2+12, mixed mode)

with Arduino 1.8.13
Comment by mirh (mirh) - Wednesday, 23 September 2020, 22:14 GMT
The bug is actually this, and it hasn't been fixed yet
https://github.com/arduino/Arduino/issues/8903

Maybe the java-runtime depend should be made >8 or something like that?
Comment by Uwe Koloska (kolewu) - Tuesday, 20 October 2020, 21:14 GMT
Problem is the wrapper script `/usr/bin/arduino` because it uses *default-runtime*. And if arduino is not build with jdk8 it does not run with jdk8 because of an incompatible change in jdk9: `ByteBuffer.flip()` returns `ByteBuffer` instead of `Buffer`.

So to fix this as a user choose a default jdk >= 8 and to fix the package make the jdk that is used to build the package a dependency and use the versioned path instead of the default.
Comment by NicoHood (NicoHood) - Wednesday, 21 October 2020, 06:38 GMT
Thanks for this important hint! So the best solution is to build with java 14 and also depend/run on java 14? Or would it also run with 11, but not with 8?
Comment by NicoHood (NicoHood) - Thursday, 13 May 2021, 09:17 GMT
It seems to only work properly with java8, so I stick to that for now.

Loading...