Skip to content

IllegalArgumentException when using Zeroconf in player #290

@iscle

Description

@iscle

Describe the bug
When running a new instance of librespot-java (Built and ran in Windows 10 x64, with JDK 15 installed), after selecting it from the Spotify dropdown menu using Zeroconf, an IllegalArgumentException gets thrown.

To Reproduce

  1. Build the dev branch (in my case, I ran Main.java from the player with IntelliJ directly);
  2. Go to Spotify client (I use Windows) and select the librespot-java instance in available devices.
  3. See the error

Expected behavior
After selecting the instance, music should begin to play (it was already playing on the official client to start).

Screenshots/Stracktraces/Logs

"C:\Program Files\Java\jdk-15.0.1\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.3\lib\idea_rt.jar=52898:C:\Program Files\JetBrains\IntelliJ IDEA 2020.3\bin" -Dfile.encoding=UTF-8 -classpath "D:\Users\Iscle\Documents\La Salle\Distribuida\librespot-java\player\target\classes;D:\Users\Iscle\Documents\La Salle\Distribuida\librespot-java\lib\target\classes;C:\Users\Iscle\.m2\repository\com\google\protobuf\protobuf-java\3.14.0\protobuf-java-3.14.0.jar;C:\Users\Iscle\.m2\repository\com\google\code\gson\gson\2.8.6\gson-2.8.6.jar;C:\Users\Iscle\.m2\repository\xyz\gianlu\zeroconf\zeroconf\1.1.3\zeroconf-1.1.3.jar;C:\Users\Iscle\.m2\repository\com\squareup\okhttp3\okhttp\4.9.0\okhttp-4.9.0.jar;C:\Users\Iscle\.m2\repository\com\squareup\okio\okio\2.8.0\okio-2.8.0.jar;C:\Users\Iscle\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib-common\1.4.0\kotlin-stdlib-common-1.4.0.jar;C:\Users\Iscle\.m2\repository\org\jetbrains\kotlin\kotlin-stdlib\1.4.10\kotlin-stdlib-1.4.10.jar;C:\Users\Iscle\.m2\repository\commons-net\commons-net\3.7.2\commons-net-3.7.2.jar;C:\Users\Iscle\.m2\repository\org\jcraft\jorbis\0.0.17\jorbis-0.0.17.jar;C:\Users\Iscle\.m2\repository\com\badlogicgames\jlayer\jlayer\1.0.2-gdx\jlayer-1.0.2-gdx.jar;C:\Users\Iscle\.m2\repository\com\electronwill\night-config\toml\3.6.3\toml-3.6.3.jar;C:\Users\Iscle\.m2\repository\com\electronwill\night-config\core\3.6.3\core-3.6.3.jar;C:\Users\Iscle\.m2\repository\org\jetbrains\annotations\20.1.0\annotations-20.1.0.jar;C:\Users\Iscle\.m2\repository\org\apache\logging\log4j\log4j-core\2.13.3\log4j-core-2.13.3.jar;C:\Users\Iscle\.m2\repository\org\apache\logging\log4j\log4j-api\2.13.3\log4j-api-2.13.3.jar;C:\Users\Iscle\.m2\repository\org\apache\logging\log4j\log4j-slf4j-impl\2.14.0\log4j-slf4j-impl-2.14.0.jar;C:\Users\Iscle\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\Iscle\.m2\repository\com\lmax\disruptor\3.4.2\disruptor-3.4.2.jar" xyz.gianlu.librespot.player.Main
2021-01-08 01:48:50,748 INFO  Utils:84 - Cryptography restrictions removal not needed.
2021-01-08 01:48:50,930 INFO  ZeroconfServer:454 - Zeroconf HTTP server started successfully on port 1367!
2021-01-08 01:48:52,393 TRACE ZeroconfServer:518 - Handling request: GET /?action=getInfo HTTP/1.1, headers: {Keep-Alive=0, User-Agent=Spotify/114800625 Win32/0 (PC laptop), Connection=keep-alive, Host=192.168.1.58, Accept-Encoding=gzip, Content-Type=application/x-www-form-urlencoded}
2021-01-08 01:48:53,067 INFO  Zeroconf:473 - Announced Service{alias='librespot-java', service='spotify-connect', port=1367, text={VERSION=1.0, CPath=/, Stack=SP}, addresses=[/192.168.1.58], domain='.local', protocol='tcp', host='DESKTOP-N234E4K'}.
2021-01-08 01:48:56,384 TRACE ZeroconfServer:518 - Handling request: GET /?action=getInfo&version=2.7.1 HTTP/1.1, headers: {Keep-Alive=0, User-Agent=Spotify/114800625 Win32/0 (PC laptop), Connection=keep-alive, Host=192.168.1.58, Accept-Encoding=gzip, Content-Type=application/x-www-form-urlencoded}
2021-01-08 01:48:57,372 TRACE ZeroconfServer:518 - Handling request: GET /?action=getInfo&version=2.7.1 HTTP/1.1, headers: {Keep-Alive=0, User-Agent=Spotify/114800625 Win32/0 (PC laptop), Connection=keep-alive, Host=192.168.1.58, Accept-Encoding=gzip, Content-Type=application/x-www-form-urlencoded}
2021-01-08 01:48:57,491 TRACE ZeroconfServer:518 - Handling request: POST / HTTP/1.1, headers: {Keep-Alive=0, User-Agent=Spotify/114800625 Win32/0 (PC laptop), Connection=keep-alive, Host=192.168.1.58, Accept-Encoding=gzip, Content-Length=776, Content-Type=application/x-www-form-urlencoded}
2021-01-08 01:48:57,562 WARN  ZeroconfServer:319 - Failed closing previous session.
java.lang.IllegalArgumentException: Argument for @NotNull parameter 'session' of xyz/gianlu/librespot/player/Main$1.sessionClosing must not be null
	at xyz.gianlu.librespot.player.Main$1.$$$reportNull$$$0(Main.java) ~[classes/:?]
	at xyz.gianlu.librespot.player.Main$1.sessionClosing(Main.java) ~[classes/:?]
	at xyz.gianlu.librespot.ZeroconfServer.lambda$closeSession$0(ZeroconfServer.java:204) ~[classes/:?]
	at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?]
	at xyz.gianlu.librespot.ZeroconfServer.closeSession(ZeroconfServer.java:203) ~[classes/:?]
	at xyz.gianlu.librespot.ZeroconfServer.handleAddUser(ZeroconfServer.java:316) ~[classes/:?]
	at xyz.gianlu.librespot.ZeroconfServer.access$200(ZeroconfServer.java:40) ~[classes/:?]
	at xyz.gianlu.librespot.ZeroconfServer$HttpRunner.handleRequest(ZeroconfServer.java:480) ~[classes/:?]
	at xyz.gianlu.librespot.ZeroconfServer$HttpRunner.handle(ZeroconfServer.java:555) ~[classes/:?]
	at xyz.gianlu.librespot.ZeroconfServer$HttpRunner.lambda$run$1(ZeroconfServer.java:463) ~[classes/:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) [?:?]
	at java.lang.Thread.run(Thread.java:832) [?:?]

Version/Commit
0e85e1a (latest dev as of this issue)

Temporary solution I came up with
Instead of catching just IOException, catch all Exceptions (Exception) in this line:

Edit: It looks like the issue is the @NotNull annotation in this line:

public void sessionClosing(@NotNull Session session) {

In this case, it can be null. Although the parameter is not used in the example code, since I don't know the original usage, I prefer you fix it in the way you think works best.

Edit 2: Well, I made a PR (#291) which IMO is the appropiate way to solve the issue :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions