What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE

** To jump to the conclusion from [here](#% E7% B5% 90% E8% AB% 96) **

Introduction

One day, when I tried to convert Groovy to Java with Convert Groovy to Java, it didn't work at all. There is no problem with the code itself, the cause is unknown, so when I looked at the log, I got this error ...

java.lang.UnsupportedOperationException
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.TypeWriter.visitDisjunctionType(TypeWriter.java:155)
	at com.intellij.psi.PsiDisjunctionType.accept(PsiDisjunctionType.java:114)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.TypeWriter.writeType(TypeWriter.java:72)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.TypeWriter.writeType(TypeWriter.java:49)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.CodeBlockGenerator.writeVariableWithoutSemicolonAndInitializer(CodeBlockGenerator.java:481)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.CodeBlockGenerator.visitCatchClause(CodeBlockGenerator.java:534)
	at org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrCatchClauseImpl.accept(GrCatchClauseImpl.java:45)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.CodeBlockGenerator.visitTryStatement(CodeBlockGenerator.java:523)
	at org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrTryCatchStatementImpl.accept(GrTryCatchStatementImpl.java:43)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.CodeBlockGenerator.visitStatementOwner(CodeBlockGenerator.java:160)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.CodeBlockGenerator.generateCodeBlock(CodeBlockGenerator.java:152)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.CodeBlockGenerator.generateMethodBody(CodeBlockGenerator.java:119)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.ClassItemGeneratorImpl.writeMethod(ClassItemGeneratorImpl.java:159)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.ClassGenerator.writeAllMethods(ClassGenerator.java:149)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.ClassGenerator.writeMembers(ClassGenerator.java:124)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.ClassGenerator.writeTypeDefinition(ClassGenerator.java:106)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.ConvertToJavaProcessor.performRefactoring(ConvertToJavaProcessor.java:93)
	at com.intellij.refactoring.BaseRefactoringProcessor.lambda$doRefactoring$11(BaseRefactoringProcessor.java:475)
	at com.intellij.refactoring.BaseRefactoringProcessor.lambda$doRefactoring$12(BaseRefactoringProcessor.java:486)
	at com.intellij.openapi.application.impl.ApplicationImpl.lambda$runWriteActionWithProgressInDispatchThread$15(ApplicationImpl.java:980)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:170)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:548)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:493)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:94)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:157)
	at com.intellij.openapi.progress.util.PotemkinProgress.runInSwingThread(PotemkinProgress.java:167)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteActionWithProgressInDispatchThread(ApplicationImpl.java:980)
	at com.intellij.refactoring.BaseRefactoringProcessor.doRefactoring(BaseRefactoringProcessor.java:486)
	at com.intellij.refactoring.BaseRefactoringProcessor.lambda$execute$4(BaseRefactoringProcessor.java:314)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:149)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:109)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:99)
	at com.intellij.refactoring.BaseRefactoringProcessor.execute(BaseRefactoringProcessor.java:312)
	at com.intellij.refactoring.BaseRefactoringProcessor.doRun(BaseRefactoringProcessor.java:243)
	at com.intellij.openapi.fileEditor.impl.NonProjectFileWritingAccessProvider.disableChecksDuring(NonProjectFileWritingAccessProvider.java:181)
	at com.intellij.refactoring.BaseRefactoringProcessor.run(BaseRefactoringProcessor.java:553)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.ConvertToJavaHandler.invokeInner(ConvertToJavaHandler.java:73)
	at org.jetbrains.plugins.groovy.refactoring.convertToJava.ConvertToJavaHandler.invoke(ConvertToJavaHandler.java:42)
	at com.intellij.refactoring.actions.BaseRefactoringAction.actionPerformed(BaseRefactoringAction.java:131)
	at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:216)
	at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:86)
	at com.intellij.openapi.application.TransactionGuardImpl.submitTransactionAndWait(TransactionGuardImpl.java:151)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:231)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.lambda$actionPerformed$0(ActionMenuItem.java:310)
	at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:911)
	at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:136)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:300)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$fireActionPerformed$0(ActionMenuItem.java:117)
	at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:86)
	at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransaction$1(TransactionGuardImpl.java:109)
	at com.intellij.openapi.application.TransactionGuardImpl.submitTransaction(TransactionGuardImpl.java:118)
	at com.intellij.openapi.application.TransactionGuard.submitTransaction(TransactionGuard.java:122)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:117)
	at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:513)
	at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:45)
	at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:533)
	at java.awt.Component.processMouseEvent(Component.java:6533)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
	at java.awt.Component.processEvent(Component.java:6298)
	at java.awt.Container.processEvent(Container.java:2236)
	at java.awt.Component.dispatchEventImpl(Component.java:4889)
	at java.awt.Container.dispatchEventImpl(Container.java:2294)
	at java.awt.Component.dispatchEvent(Component.java:4711)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
	at java.awt.Container.dispatchEventImpl(Container.java:2280)
	at java.awt.Window.dispatchEventImpl(Window.java:2746)
	at java.awt.Component.dispatchEvent(Component.java:4711)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
	at java.awt.EventQueue$4.run(EventQueue.java:731)
	at java.awt.EventQueue$4.run(EventQueue.java:729)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:821)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:645)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:365)
	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)

WTF !? What the hell The second line from the top of this stack trace

at org.jetbrains.plugins.groovy.refactoring.convertToJava.TypeWriter.visitDisjunctionType(TypeWriter.java:155)

To investigate

Investigation

visitDisjunctionType If you search for visitDisjunctionType, you will find this [thing](https://github.com/JetBrains/intellij-community/blob/303edac/java/java-psi-api/src/com/intellij/psi/ PsiTypeVisitor.java # L62).

  @Override
  public Object visitDisjunctionType(@NotNull PsiDisjunctionType disjunctionType) {
    //it is not available in groovy source code
    throw new UnsupportedOperationException();
  }

That's an error. Apparently, the argument PsiDisjunctionType represents a specification like ʻA | B`.

What else is wrong?

It seems that PsiType appears, but I'm not sure.

Conclusion

It worked when I changed it appropriately. If you think you can't convert something, look for ʻA | B. It may be in the type specification part of the catch` clause. (I wonder if there is something else ...?)

Recommended Posts

What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE
What to do if you get a groovy warning in Thymeleaf Layout
What do you use when converting to String?
What to do when IllegalStateException occurs in PlayFramework
When you want to dynamically replace Annotation in Java8
What to do if Command line is too long appears when building a gradle project in Intellij IDEA
What to do if you can't get the text of an element in Selenium
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do if you get a java.io.IOException in GlassFish
What to do when Method not found in f: ajax
What to do when you launch an application with rails
What to do if you can't use the rails command
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
Do HelloWorld in Java / IntelliJ / Gradle
Java + OpenCV 3.X in IntelliJ IDEA
What to do when javax.batch.operations.JobStartException occurs
Do you use Stream in Java?
What to do if you get a gcc error in Docker
What to do when the changes in the Servlet are not reflected
What to do if you get a DISPLAY error in gym.render ()
What to do when you become a Problem During Content Assist
What to do when you run into a docker-compose node_modules problem
What to do if you forget the root password in CentOS7
[Rails] What to do if you can't get parameters with form_with
What to do when you want to know the source position where the method is defined in binding.pry
What to do if you get a JNI shared library error when trying to build in Eclipse
[IntelliJ IDEA] How to automatically add final when saving a Java file
What to do when a javax.el.PropertyNotWritableException occurs
What to do if you can't install the plugin from the Eclipse marketplace
How to do base conversion in Java
Optimize Java import declarations in IntelliJ IDEA
What to do when Blocked Host: "host name" appears in Ruby on Rails
What to do and how to install when an error occurs in DXRuby 1.4.7
The first thing to do when you want to be happy with Heroku on GitHub with Eclipse in Java
What to do if you can't bundle update and bundle install after installing Ruby 3.0.0 in the Rails tutorial
What to do if tomcat process remains when tomcat is stopped in eclipse
What to do if Operation not permitted is displayed when you execute a command in the terminal
What to do if you get an error when you hit Heroku logs
What to do if you install Ubuntu
What to do when undefined method ʻuser_signed_in?'
Java --Introduce CheckStyle plugin to IntelliJ IDEA and reflect it in formatter
Notes on what to do when a WebView ClassNotFoundException occurs in JavaFX 12
What to do when you want to delete a migration file that is "NO FILE"
<f: ajax> Unable to attach <f: ajax> to non-ClientBehaviorHolder What to do when you become a parent
Deploy Java application developed in IntelliJ IDEA environment to Alibaba Cloud ECS instance
What to do if you can't activate the select box created by bootstrap-select
What to do when the value becomes null in the second getSubmittedValue () in JSF Validator
What to do when rails db: seed does not reflect in the database
What to do if you have installed Java for OS X on macOS
What to do when "Nil location provided. Can't build URI." Appears on CarrierWave
What to do if ffi installation fails when launching an application in Rails
Settings to display Japanese Javadoc in IntelliJ IDEA
When you want to bind InputStream in JDBI3
A note when you want Tuple in Java
What to do if you push incorrect information
What I did when I converted java to Kotlin
What to do when debugging "Source not found"
[Java] What to do if you get an error in Eclipse saying "Not allowed at source level below 1.X"
What to do if you can't find the JDK you put in SDKMAN after migrating from bash to zsh on macOS
[React.useRef] What to do when the latest state cannot be referenced in the event listener
What to do if you get a wrong number of arguments error in binding.pry