dubreuia / intellij-plugin-save-actions

Supports configurable, Eclipse like, save actions, including "organize imports", "reformat code" and "rearrange code".
MIT License
529 stars 102 forks source link

Exception with IntelliJ IDEA 2018.3 EAP #190

Closed kedar-joshi closed 6 years ago

kedar-joshi commented 6 years ago

Save actions plugin throws following exception when used with IDEA v2018.3 EAP

java.lang.NoClassDefFoundError: Could not initialize class com.dubreuia.processors.java.JavaProcessor
    at com.dubreuia.processors.java.ProcessorFactory.getSaveActionsProcessors(ProcessorFactory.java:17)
    at com.dubreuia.core.component.java.SaveActionManager.getSaveActionsProcessors(SaveActionManager.java:28)
    at com.dubreuia.core.component.SaveActionManager.processPsiFile(SaveActionManager.java:75)
    at com.dubreuia.core.component.SaveActionManager.processPsiFileIfNecessary(SaveActionManager.java:70)
    at com.dubreuia.core.action.ShortcutAction.lambda$actionPerformed$1(ShortcutAction.java:30)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1376)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
    at com.dubreuia.core.action.ShortcutAction.actionPerformed(ShortcutAction.java:30)
    at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:258)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:275)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$1.performAction(IdeKeyEventDispatcher.java:620)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$processAction$2(IdeKeyEventDispatcher.java:669)
    at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:195)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:668)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.java:520)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:475)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:212)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:642)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:366)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

I use ctrl + shift + s combination for triggering save actions but it fails with above exception every time.

kedar-joshi commented 6 years ago

Please let me know if you need any additional information.

phazebroek commented 6 years ago

I am also facing this issue on Mac using cmd+s and IntelliJ:

IntelliJ IDEA 2018.3 EAP (Ultimate Edition) Build #IU-183.2153.8, built on September 4, 2018 IntelliJ IDEA EAP User Expiration date: October 4, 2018 JRE: 1.8.0_152-release-1293-b10 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.13.6

NikolayMetchev commented 6 years ago

I'm getting a slightly different stack trace: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: com/siyeh/ig/serialization/SerializableHasSerialVersionUIDFieldInspectionBase at com.dubreuia.processors.java.JavaProcessor.(JavaProcessor.java:71) at com.dubreuia.processors.java.ProcessorFactory.getSaveActionsProcessors(ProcessorFactory.java:17) at com.dubreuia.core.component.java.SaveActionManager.getSaveActionsProcessors(SaveActionManager.java:28) at com.dubreuia.core.component.SaveActionManager.processPsiFile(SaveActionManager.java:75) at com.dubreuia.core.component.SaveActionManager.processPsiFileIfNecessary(SaveActionManager.java:70) at com.dubreuia.core.component.SaveActionManager.beforeDocumentSaving(SaveActionManager.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(MessageBusConnectionImpl.java:117) at com.intellij.util.messages.impl.MessageBusImpl.doPumpMessages(MessageBusImpl.java:397) at com.intellij.util.messages.impl.MessageBusImpl.pumpWaitingBuses(MessageBusImpl.java:358) at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:347) at com.intellij.util.messages.impl.MessageBusImpl.sendMessage(MessageBusImpl.java:324) at com.intellij.util.messages.impl.MessageBusImpl.access$200(MessageBusImpl.java:29) at com.intellij.util.messages.impl.MessageBusImpl$2.invoke(MessageBusImpl.java:196) at com.sun.proxy.$Proxy29.beforeDocumentSaving(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.multiCast(FileDocumentManagerImpl.java:141) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.lambda$new$0(FileDocumentManagerImpl.java:121) at com.sun.proxy.$Proxy29.beforeDocumentSaving(Unknown Source) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.lambda$doSaveDocumentInWriteAction$4(FileDocumentManagerImpl.java:424) at com.intellij.pom.core.impl.PomModelImpl.guardPsiModificationsIn(PomModelImpl.java:402) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.doSaveDocumentInWriteAction(FileDocumentManagerImpl.java:423) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.lambda$doSaveDocument$2(FileDocumentManagerImpl.java:385) at com.intellij.openapi.application.WriteAction.run(WriteAction.java:105) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.doSaveDocument(FileDocumentManagerImpl.java:385) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:304) at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:282) at com.intellij.openapi.components.impl.stores.StoreUtil.saveDocumentsAndProjectsAndApp(StoreUtil.java:112) at com.intellij.ide.actions.SaveAllAction.actionPerformed(SaveAllAction.java:23) at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:258) at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:275) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$1.performAction(IdeKeyEventDispatcher.java:620) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$processAction$2(IdeKeyEventDispatcher.java:669) at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:195) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:668) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.java:520) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:475) at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:212) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:642) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:366) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) Caused by: java.lang.NoClassDefFoundError: com/siyeh/ig/serialization/SerializableHasSerialVersionUIDFieldInspectionBase ... 52 more Caused by: java.lang.ClassNotFoundException: com.siyeh.ig.serialization.SerializableHasSerialVersionUIDFieldInspectionBase PluginClassLoader[com.dubreuia, 1.1.0] com.intellij.ide.plugins.cl.PluginClassLoader@5704eabc at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:49) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 52 more

dubreuia commented 6 years ago

Hey guys, thanks a lot for reporting.

It seems like they removed an inspection that I was using. I'm fixing this ASAP.

dubreuia commented 6 years ago

tl;dr; The problem is that the class was named com.siyeh.ig.serialization.SerializableHasSerialVersionUIDFieldInspectionBase (SDK 2016.1), it is now named com.siyeh.ig.serialization.SerializableHasSerialVersionUIDFieldInspection (SDK 2018.3).

Long version: I've fixed it in the "fix" branch. It was harder to fix then I thought, because I wanted to copy / paste the inspection in our code (like we do with other inspections because we cannot extend them), but it turns out the inspection would be calling protected method in parent class, which is authorized only if the parent class is in the same classloader (which is not the case because plugins are in a separate classloader). See https://stackoverflow.com/a/10538366

So I'm loading the inspection by reflection. It is executed only once (the inspection is then stored in a singleton) so performance is not a problem.

The best way to fix this would be to build multiple versions for multiple targets (see #145, basically one target before 2018.3 and one target for 2018.3 and onward), but it takes a lot more work and it feels overkill for now.

rw00 commented 6 years ago

@dubreuia Could you please release this as a patch if you intend to delay the milestone release? Thanks,

dubreuia commented 6 years ago

I'm going to release it tomorrow, I need to test it a bit before release.

You can use this package: Save Actions-1.2.0.zip

kedar-joshi commented 6 years ago

Attached plugin works as expected. No more exceptions.

dubreuia commented 6 years ago

Released in 1.2.0

dubreuia commented 6 years ago

Thanks a lot guy for reporting and commenting and testing. I really appreciate it!

phazebroek commented 6 years ago

Thx for the patch, works like a charm!