maximilianvoss / musicsync

Syncing your Toniebox with Spotify Playlists
Apache License 2.0
104 stars 31 forks source link

Exception in thread "main" java.lang.NullPointerException #18

Closed Rheinlaender closed 3 years ago

Rheinlaender commented 4 years ago

First: great project!

unfortunately I’m getting the following error:

Exception in thread "main" java.lang.NullPointerException at rocks.voss.musicsync.Application.sync(Application.java:61) at rocks.voss.musicsync.Application.main(Application.java:52)

I run on: openjdk version "1.8.0_265" OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~16.04-b01) OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)

From my understanding it has something to with the input connection… Any ideas?

maximilianvoss commented 3 years ago

Did you run v2.0?

ripcurlx commented 3 years ago

I see the same error when running the v2.0 branch. I tried out master first, but unfortunately it also fails when trying to login at tonie.

ripcurlx commented 3 years ago

It fails as the PluginLoader.getInputPlugins() map is empty when trying to get the getSyncInputPlugin based on the input schema.

maximilianvoss commented 3 years ago

How do you start the application? what is in the classpath?

ripcurlx commented 3 years ago

First I tried to run it after a clean maven build with ./musicsync --input spotify:playlist:[MY_PLAYLIST] --output toniebox:[HOUSEHOLD_ID]:[CREATIVE_TONIE_ID] receiving following exception

Exception in thread "main" java.lang.NullPointerException
    at rocks.voss.musicsync.Application.sync(Application.java:61)
    at rocks.voss.musicsync.Application.main(Application.java:52)

running on macOS 10.15.7 using Java 10.0.2 and afterwards I tried to debug it in IntelliJ compiling with Java 11.0.8 using classpath of module musicsync-application.

maximilianvoss commented 3 years ago

Hi, only JDK8 is supported as of now

ripcurlx commented 3 years ago

Thanks! Wasn't aware about that. I gave it a quick shot with Java 1.8.0_27 and didn't see any exception when running ./musicsync --input spotify:playlist:[MY_PLAYLIST] --output toniebox:[HOUSEHOLD_ID]:[CREATIVE_TONIE_ID], but also nothing else happened (nothing logged in musicsync.log). I quickly ran it again in IntelliJ with 1.8.0_27 and still see the same exception mentioned above.

maximilianvoss commented 3 years ago

can you please paste the output if you only run ./musicsync

ripcurlx commented 3 years ago
Usage: spotify-toniebox-sync.jar [--daemon | --input INPUT --output OUTPUT]
--daemon
        Run in daemon mode to sync periodically all lists in the properties file
--input INPUT
        Define an input source for a one-time run
--output OUTPUT
        Define an output destination for a one-time run

Input Plugins:
--spotify-apicode
        Generate an API Code URL to get attach Application to Spotify Account
--spotify-code CODE
        Generate a Refresh token out of the Spotify Code

Output Plugins:
--toniebox-username USERNAME
        Set the Toniebox username to login to Toniebox
--toniebox-password PASSWORD
        Set the password for the Toniebox user for login
--filesystem-directory DIRECTORY
        Set the output path for the files
maximilianvoss commented 3 years ago

thanks, will have a deeper look into this

cg-laser commented 3 years ago

In case it helps, I'm running into the same problem (on Ubuntu18.04 installed in a virtual machine and JDK8)

./musicsync --input spotify:playlist:XXXXX --output toniebox:XXXX-XXXXX
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
    at rocks.voss.musicsync.plugins.output.toniebox.TonieboxConnection.createBy(TonieboxConnection.java:16)
    at rocks.voss.musicsync.plugins.output.toniebox.TonieboxOutputPlugin.getCreativeTonie(TonieboxOutputPlugin.java:185)
    at rocks.voss.musicsync.plugins.output.toniebox.TonieboxOutputPlugin.isTrackUploaded(TonieboxOutputPlugin.java:54)
    at rocks.voss.musicsync.Application.sync(Application.java:67)
    at rocks.voss.musicsync.Application.main(Application.java:52)
matthiastz commented 3 years ago

It fails as the PluginLoader.getInputPlugins() map is empty when trying to get the getSyncInputPlugin based on the input schema.

Can confirm.

I was debugging into this and wondering, why PluginLoader.loadPlugins() in Application:31 does not seem to init the two maps inputPlugins/outputPlugins respectively - isn't that a possible cause for the problem? Because with empty map(s) PluginLoader.get...Plugins().get(getInputSchema()) will always fail

(edit: tried this on both git branches via musicsync script, IntelliJ Java 1.8.0_211 and also created a custom dockerfile)

Kondamon commented 3 years ago

Can confirm the issue as well. Wanted to debug it with VS Code on MacOS but getting a lot of errors like The type SyncConnectionImpl must implement the inherited abstract method SyncConnection.getOutputUri(). I'm a JAVA newbie and I don't know if this is related to wrong settings in my VS instance.

However, I noticed that the mp3 file is not saved into the specified directory (just remains empty) and then I‘m getting a FileIO acces error stating that the file doesn‘t exist before the upload to tonies starts. After changing the output to file-system, I receive the „NullPointer-error“ described above.

matthiastz commented 3 years ago

Responding to my own comment above: I think I found something. I am far away from being an expert in maven or Java Reflections, but as I again was debugging this project, the mentioned two HashMaps in PluginLoader.loadPlugins() where not correctly instantiated (always empty).

Somehow Reflections were not able to find the Subtype Classes like e.g. SpotifyInputPlugin etc. So for now I just created a hard dependency from the PluginLoader (application maven subproject) to plugins subproject. I know this is maybe not clean, but can be a workaround.

For me locally the NPE seems to be gone.

edit: this can maybe be fixed more cleanly by using a more specific reflection approach that is fitting to this project setup and Java version, a somehow similar discussion was already done here: https://github.com/maximilianvoss/spotify-toniebox-sync/issues/11

maximilianvoss commented 3 years ago

Just an Idea. Do you use OpenJDK or the Oracle one? Tried it successfully with the Oracle Version on my Ubuntu server

matthiastz commented 3 years ago

Thanks for the hint. Tried it with both OpenJDK-8 and oracle64-1.8.0.211 on my Mac and in Docker.

cg-laser commented 3 years ago

Maybe this helps in debugging. I followed the hint and installed the oracle version (instead of OpenJDK) version 1.8.0._271 on Ubutu18.04 that I run in a virtual machine. I still get an error but a slightly different one. The error occurs a few second into running musicsync.

03 Jan 2021 21:28:06,529 - ERROR:rocks.voss.musicsync.Application:main:47: Exception
java.lang.ArrayIndexOutOfBoundsException: 2
    at rocks.voss.musicsync.plugins.output.toniebox.TonieboxConnection.createBy(TonieboxConnection.java:16)
    at rocks.voss.musicsync.plugins.output.toniebox.TonieboxOutputPlugin.getCreativeTonie(TonieboxOutputPlugin.java:185)
    at rocks.voss.musicsync.plugins.output.toniebox.TonieboxOutputPlugin.isTrackUploaded(TonieboxOutputPlugin.java:54)
    at rocks.voss.musicsync.Application.sync(Application.java:67)
    at rocks.voss.musicsync.Application.main(Application.java:42)
schniedan commented 3 years ago

Hi, I started with this error on "ubuntu-20.04.2.0-desktop-amd64", too. I solved it by:

schniedan commented 3 years ago

Ok, so the error came back for me, too.

I did some debugging: It looks like it can't initialise the spotify input plugin. The plugin map in the PluginLoader.java is empty -> getSyncInputPlugin() in SyncConnectionImpl returns null...

I'm wondering if I forgot to recompile anything anywhere? Any ideas there?

maximilianvoss commented 3 years ago

I haven't found any way to reproduce the issues yet. Running on Ubuntu 18.04 LTS and Oracle JDK just fine :-/

speisz commented 3 years ago

Adding plugin dependencies explicitely in appication/pom.xml solved the issue of reflection not finding any plugin subtypes for me.

        <dependency>
            <groupId>rocks.voss</groupId>
            <artifactId>musicsync-plugins-input-spotify</artifactId>
            <version>2.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>rocks.voss</groupId>
            <artifactId>musicsync-plugins-output-filesystem</artifactId>
            <version>2.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>rocks.voss</groupId>
            <artifactId>musicsync-plugins-output-toniebox</artifactId>
            <version>2.0-SNAPSHOT</version>
        </dependency>

Edit: At least when starting from withing the IDE... Using the output of mvn install in package does not yet work for me.

maximilianvoss commented 3 years ago

fixed in latest version