esensar/neovim-java

"Missing creator for ui event" exception

fan-tom opened this issue · 4 comments

I try to use NeovimStreamNotificationHandler to get ui notifications.

var notificationHandler = new NeovimStreamNotificationHandler(reactiveRpcStreamer);
notificationHandler.uiEvents().subscribe(subscriber);

but get such exception when such notification is received

398 [pool-1-thread-1] INFO com.ensarsarajcic.neovim.java.corerpc.client.PackStream  - Notification received: NotificationMessage{name='redraw', arguments=[[option_set, ...
422 [ForkJoinPool.commonPool-worker-11] ERROR com.ensarsarajcic.neovim.java.notifications.NeovimStreamNotificationHandler  - Missing creator for ui event {}option_set
java.lang.NullPointerException
	at com.ensarsarajcic.neovim.java.notifications.NeovimStreamNotificationHandler.lambda$eventFromRawData$4(NeovimStreamNotificationHandler.java:124)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)

It is thrown here

// com.ensarsarajcic.neovim.java.notifications.NeovimStreamNotificationHandler#eventFromRawData
...
return NotificationCreatorCollector.getUIEventCreators().get(name).apply(o);
...

because getUIEventCreators() returns empty dict.
Seems that it cannot find ui event model classes using reflection

Not sure what might go wrong there...
Which version are you using?
Do you use any kind of code obfuscator, that might break reflection?

No, I don't use any obfuscation, it seems to be reflection issue, but I don't fully understand what it is. I, however, managed to fix it locally, replacing class finding algorithm with this one https://stackoverflow.com/a/58773038/7286194. One of the differences between it and your original algo is that new one uses java.nio.file.FileSystem, while old one uses java.io.File. I'm not an expert in java/jvm, that's why I cannot say, why old method doesn't work and new one does.
My platform is macOS Mojave 10.14.6, jdk 11.0.1, if it says something. Feel free to request any additional info. I also can make PR with my fix, but I think we must understand what is the problem first
PS: I use 0.2.0-SNAPSHOT, but can replay using 0.1.6 too

Feel free to make a PR. I am not really sure why is that failing, I will try and investigate.

Apparently original solution had an issue if path to the project had spaces in it. In my case there were no spaces, but once I added spaces to the path, I could reproduce the issue.

Issue found in comment to this solution: https://stackoverflow.com/a/520344/6721708

By changing code per first comment, it worked:

  I had a problem with this if my path included spaces. The URL class was escaping spaces to %20, but the new File() 
  constructor treated that as a literal percent sign two zero. I fixed it by changing the dirs.add(...) line to this: dirs.add(new 
  File(resource.toURI())); This also meant I had to add URISyntaxException to the throws clause of getClasses 

If you want you can make a PR to change it to nio package, otherwise I will fix it in a couple of days.