From 2cffa6f698fa3bcdcf4d1bd63f0039ae37b28fe8 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 13 Aug 2013 16:44:22 +0200 Subject: [PATCH] EA-48744 com.intellij.openapi.options.ConfigurationException: Invalid port: '513188' cleanup IDEA requires JDK >1.6 --- .../apiAdapters/TransportServiceWrapper.java | 18 ++++------- .../debugger/impl/DebuggerUtilsImpl.java | 22 ++++++++++--- ...cDebuggerParametersRunnerConfigurable.java | 31 +++++++++---------- .../debugger/impl/GenericDebuggerRunner.java | 6 ++++ .../impl/GenericDebuggerRunnerSettings.java | 6 ++++ ...DebuggerParametersPatcherConfigurable.form | 14 +++------ .../debugger/engine/DebuggerUtils.java | 17 +++++----- .../execution/remote/RemoteConfiguration.java | 5 +++ .../src/com/intellij/ui/PortField.java | 6 +++- .../src/messages/DebuggerBundle.properties | 2 +- 10 files changed, 74 insertions(+), 53 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/apiAdapters/TransportServiceWrapper.java b/java/debugger/impl/src/com/intellij/debugger/apiAdapters/TransportServiceWrapper.java index a464864743b2..84a4679919ba 100644 --- a/java/debugger/impl/src/com/intellij/debugger/apiAdapters/TransportServiceWrapper.java +++ b/java/debugger/impl/src/com/intellij/debugger/apiAdapters/TransportServiceWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package com.intellij.debugger.apiAdapters; import com.intellij.execution.ExecutionException; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.SystemInfo; import com.intellij.util.ArrayUtil; import com.sun.jdi.connect.Transport; @@ -25,8 +24,8 @@ import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Map; import java.util.HashMap; +import java.util.Map; /** * @author max @@ -36,14 +35,9 @@ public class TransportServiceWrapper { private final Object myDelegateObject; private final Class myDelegateClass; - @SuppressWarnings({"HardCodedStringLiteral"}) - private static final String SOCKET_TRANSPORT_CLASS = SystemInfo.JAVA_VERSION.startsWith("1.4") - ? "com.sun.tools.jdi.SocketTransport" - : "com.sun.tools.jdi.SocketTransportService"; - @SuppressWarnings({"HardCodedStringLiteral"}) - private static final String SHMEM_TRANSPORT_CLASS = SystemInfo.JAVA_VERSION.startsWith("1.4") - ? "com.sun.tools.jdi.SharedMemoryTransport" - : "com.sun.tools.jdi.SharedMemoryTransportService"; + + private static final String SOCKET_TRANSPORT_CLASS = "com.sun.tools.jdi.SocketTransportService"; + private static final String SHMEM_TRANSPORT_CLASS = "com.sun.tools.jdi.SharedMemoryTransportService"; private final Map myListenAddresses = new HashMap(); @@ -172,7 +166,7 @@ public class TransportServiceWrapper { transport = new TransportServiceWrapper(Class.forName(SHMEM_TRANSPORT_CLASS)); } } - catch (UnsatisfiedLinkError e) { + catch (UnsatisfiedLinkError ignored) { transport = new TransportServiceWrapper(Class.forName(SOCKET_TRANSPORT_CLASS)); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java index 269799d07624..6be6899d6bb0 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,23 +45,28 @@ import java.io.IOException; public class DebuggerUtilsImpl extends DebuggerUtilsEx{ private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.impl.DebuggerUtilsImpl"); + @Override public PsiExpression substituteThis(PsiExpression expressionWithThis, PsiExpression howToEvaluateThis, Value howToEvaluateThisValue, StackFrameContext context) throws EvaluateException { return DebuggerTreeNodeExpression.substituteThis(expressionWithThis, howToEvaluateThis, howToEvaluateThisValue); } + @Override public EvaluatorBuilder getEvaluatorBuilder() { return EvaluatorBuilderImpl.getInstance(); } + @Override public DebuggerTreeNode getSelectedNode(DataContext context) { return DebuggerAction.getSelectedNode(context); } + @Override public DebuggerContextImpl getDebuggerContext(DataContext context) { return DebuggerAction.getDebuggerContext(context); } + @Override @SuppressWarnings({"HardCodedStringLiteral"}) public Element writeTextWithImports(TextWithImports text) { Element element = new Element("TextWithImports"); @@ -71,6 +76,7 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{ return element; } + @Override @SuppressWarnings({"HardCodedStringLiteral"}) public TextWithImports readTextWithImports(Element element) { LOG.assertTrue("TextWithImports".equals(element.getName())); @@ -83,39 +89,45 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{ } } + @Override public void writeTextWithImports(Element root, String name, TextWithImports value) { LOG.assertTrue(value.getKind() == CodeFragmentKind.EXPRESSION); JDOMExternalizerUtil.writeField(root, name, value.toExternalForm()); } + @Override public TextWithImports readTextWithImports(Element root, String name) { String s = JDOMExternalizerUtil.readField(root, name); if(s == null) return null; return new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, s); } + @Override public TextWithImports createExpressionWithImports(String expression) { return new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, expression); } + @Override public PsiElement getContextElement(StackFrameContext context) { return PositionUtil.getContextElement(context); } + @Override public PsiClass chooseClassDialog(String title, Project project) { TreeClassChooser dialog = TreeClassChooserFactory.getInstance(project).createAllProjectScopeChooser(title); dialog.showDialog(); return dialog.getSelected(); } + @Override public CompletionEditor createEditor(Project project, PsiElement context, String recentsId) { return new DebuggerExpressionComboBox(project, context, recentsId, DefaultCodeFragmentFactory.getInstance()); } + @Override public String findAvailableDebugAddress(final boolean useSockets) throws ExecutionException { final TransportServiceWrapper transportService = TransportServiceWrapper.getTransportService(useSockets); - - if(useSockets) { + if (useSockets) { final int freePort; try { freePort = NetUtils.findAvailableSocketPort(); @@ -127,7 +139,7 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{ } try { - String address = transportService.startListening(); + String address = transportService.startListening(); transportService.stopListening(address); return address; } @@ -135,4 +147,4 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{ throw new ExecutionException(DebugProcessImpl.processError(e)); } } -} +} \ No newline at end of file diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerParametersRunnerConfigurable.java b/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerParametersRunnerConfigurable.java index b0cb440e039f..b36d0a4303fe 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerParametersRunnerConfigurable.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerParametersRunnerConfigurable.java @@ -25,6 +25,7 @@ import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.PortField; import com.intellij.xdebugger.impl.settings.DebuggerConfigurable; import org.jetbrains.annotations.NotNull; @@ -38,7 +39,7 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< private JTextField myAddressField; private JPanel myShMemPanel; private JPanel myPortPanel; - private JTextField myPortField; + private PortField myPortField; private boolean myIsLocal = false; private JButton myDebuggerSettings; private JRadioButton mySocketTransport; @@ -47,6 +48,7 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< public GenericDebuggerParametersRunnerConfigurable(final Project project) { myDebuggerSettings.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { ShowSettingsUtil.getInstance().showSettingsDialog(project, DebuggerConfigurable.DISPLAY_NAME); if (myIsLocal) { @@ -58,6 +60,7 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< }); final ActionListener listener = new ActionListener() { + @Override public void actionPerformed(final ActionEvent e) { suggestAvailablePortIfNotSpecified(); updateUI(); @@ -80,6 +83,7 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< return getTransport() == DebuggerSettings.SOCKET_TRANSPORT; } + @Override @NotNull public JComponent createEditor() { return myPanel; @@ -94,9 +98,11 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< myShmemTransport.setEnabled(!myIsLocal); } + @Override public void disposeEditor() { } + @Override public void resetEditorFrom(GenericDebuggerRunnerSettings runnerSettings) { setIsLocal(runnerSettings.LOCAL); setTransport(runnerSettings.getTransport()); @@ -113,7 +119,7 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< try { Integer.parseInt(port); } - catch (NumberFormatException e) { + catch (NumberFormatException ignored) { portSpecified = false; } } @@ -139,7 +145,7 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< private String getPort() { if (isSocket()) { - return myPortField.getText(); + return String.valueOf(myPortField.getNumber()); } else { return myAddressField.getText(); @@ -147,16 +153,9 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< } private void checkPort() throws ConfigurationException { - if (isSocket() && myPortField.getText().length() > 0) { - try { - final int port = Integer.parseInt(myPortField.getText()); - if (port < 0 || port > 0xffff) { - throw new NumberFormatException(); - } - } - catch (NumberFormatException e) { - throw new ConfigurationException(DebuggerBundle.message("error.text.invalid.port.0", myPortField.getText())); - } + final int port = myPortField.getNumber(); + if (isSocket() && port > 0 && (port < 0 || port > 0xffff)) { + throw new ConfigurationException(DebuggerBundle.message("error.text.invalid.port.0", port)); } } @@ -173,13 +172,14 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< private void setPort(String port) { if (isSocket()) { - myPortField.setText(port); + myPortField.setNumber(StringUtil.parseInt(port, 0)); } else { myAddressField.setText(port); } } + @Override public void applyEditorTo(GenericDebuggerRunnerSettings runnerSettings) throws ConfigurationException { runnerSettings.LOCAL = myIsLocal; checkPort(); @@ -188,5 +188,4 @@ public class GenericDebuggerParametersRunnerConfigurable extends SettingsEditor< runnerSettings.setTransport(getTransport()); } } - -} +} \ No newline at end of file diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java b/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java index 0d2c516a55f6..138da8074e53 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java @@ -33,16 +33,19 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class GenericDebuggerRunner extends JavaPatchableProgramRunner { + @Override public boolean canRun(@NotNull final String executorId, @NotNull final RunProfile profile) { return executorId.equals(DefaultDebugExecutor.EXECUTOR_ID) && profile instanceof ModuleRunProfile && !(profile instanceof RunConfigurationWithSuppressedDefaultDebugAction); } + @Override @NotNull public String getRunnerId() { return DebuggingRunnerData.DEBUGGER_RUNNER_ID; } + @Override protected RunContentDescriptor doExecute(final Project project, final RunProfileState state, final RunContentDescriptor contentToReuse, @@ -95,10 +98,12 @@ public class GenericDebuggerRunner extends JavaPatchableProgramRunner getSettingsEditor(final Executor executor, RunConfiguration configuration) { if (configuration instanceof RunConfigurationWithRunnerSettings) { if (((RunConfigurationWithRunnerSettings)configuration).isSettingsNeeded()) { diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunnerSettings.java b/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunnerSettings.java index fd3279572077..594aec895b59 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunnerSettings.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunnerSettings.java @@ -31,18 +31,22 @@ public class GenericDebuggerRunnerSettings implements RunnerSettings, DebuggingR public GenericDebuggerRunnerSettings() { } + @Override public String getDebugPort() { return DEBUG_PORT; } + @Override public boolean isRemote() { return !LOCAL; } + @Override public void setLocal(boolean isLocal) { LOCAL = isLocal; } + @Override public void setDebugPort(String port) { DEBUG_PORT = port; } @@ -51,10 +55,12 @@ public class GenericDebuggerRunnerSettings implements RunnerSettings, DebuggingR TRANSPORT = transport; } + @Override public void readExternal(Element element) throws InvalidDataException { DefaultJDOMExternalizer.readExternal(this, element); } + @Override public void writeExternal(Element element) throws WriteExternalException { DefaultJDOMExternalizer.writeExternal(this, element); } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/GenericDebuggerParametersPatcherConfigurable.form b/java/debugger/impl/src/com/intellij/debugger/ui/GenericDebuggerParametersPatcherConfigurable.form index 01cb7956c2bd..3cb1ef9bf190 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/GenericDebuggerParametersPatcherConfigurable.form +++ b/java/debugger/impl/src/com/intellij/debugger/ui/GenericDebuggerParametersPatcherConfigurable.form @@ -3,7 +3,7 @@ - + @@ -39,7 +39,7 @@ - + @@ -52,15 +52,11 @@ - + - - - + - - - + diff --git a/java/debugger/openapi/src/com/intellij/debugger/engine/DebuggerUtils.java b/java/debugger/openapi/src/com/intellij/debugger/engine/DebuggerUtils.java index 9fcc7d7a7d8d..e2f93e7ba50e 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/engine/DebuggerUtils.java +++ b/java/debugger/openapi/src/com/intellij/debugger/engine/DebuggerUtils.java @@ -107,7 +107,7 @@ public abstract class DebuggerUtils { toStringMethod = findMethod(refType, "toString", "()Ljava/lang/String;"); debugProcess.putUserData(TO_STRING_METHOD_KEY, toStringMethod); } - catch (Exception e) { + catch (Exception ignored) { throw EvaluateExceptionUtil.createEvaluateException( DebuggerBundle.message("evaluation.error.cannot.evaluate.tostring", objRef.referenceType().name())); } @@ -125,7 +125,7 @@ public abstract class DebuggerUtils { } throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.unsupported.expression.type")); } - catch (ObjectCollectedException e) { + catch (ObjectCollectedException ignored) { throw EvaluateExceptionUtil.OBJECT_WAS_COLLECTED; } } @@ -291,8 +291,8 @@ public abstract class DebuggerUtils { } List ifaces = ((ClassType)subType).allInterfaces(); - for (Iterator iterator = ifaces.iterator(); iterator.hasNext();) { - InterfaceType interfaceType = (InterfaceType)iterator.next(); + for (Object iface : ifaces) { + InterfaceType interfaceType = (InterfaceType)iface; if (interfaceType.name().equals(superType)) { return interfaceType; } @@ -302,8 +302,8 @@ public abstract class DebuggerUtils { if (subType instanceof InterfaceType) { List ifaces = ((InterfaceType)subType).superinterfaces(); - for (Iterator iterator = ifaces.iterator(); iterator.hasNext();) { - InterfaceType interfaceType = (InterfaceType)iterator.next(); + for (Object iface : ifaces) { + InterfaceType interfaceType = (InterfaceType)iface; result = getSuperType(interfaceType, superType); if (result != null) { return result; @@ -402,9 +402,8 @@ public abstract class DebuggerUtils { PsiElement[] children = codeFragment.getChildren(); if(children.length == 0) throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.empty.code.fragment")); - for (int i = 0; i < children.length; i++) { - PsiElement child = children[i]; - if(child instanceof PsiErrorElement) { + for (PsiElement child : children) { + if (child instanceof PsiErrorElement) { throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.invalid.expression", child.getText())); } } diff --git a/java/execution/impl/src/com/intellij/execution/remote/RemoteConfiguration.java b/java/execution/impl/src/com/intellij/execution/remote/RemoteConfiguration.java index 450aeb546cab..4f503f3f7270 100644 --- a/java/execution/impl/src/com/intellij/execution/remote/RemoteConfiguration.java +++ b/java/execution/impl/src/com/intellij/execution/remote/RemoteConfiguration.java @@ -44,6 +44,7 @@ import java.util.Collection; public class RemoteConfiguration extends ModuleBasedConfiguration implements RunConfigurationWithSuppressedDefaultRunAction { + @Override public void writeExternal(final Element element) throws WriteExternalException { super.writeExternal(element); final Module module = getConfigurationModule().getModule(); @@ -53,6 +54,7 @@ public class RemoteConfiguration extends ModuleBasedConfiguration getConfigurationEditor() { SettingsEditorGroup group = new SettingsEditorGroup(); @@ -89,6 +93,7 @@ public class RemoteConfiguration extends ModuleBasedConfiguration getValidModules() { return getAllModules(); } diff --git a/platform/platform-api/src/com/intellij/ui/PortField.java b/platform/platform-api/src/com/intellij/ui/PortField.java index 48debf6b54a9..6d139fb5b911 100644 --- a/platform/platform-api/src/com/intellij/ui/PortField.java +++ b/platform/platform-api/src/com/intellij/ui/PortField.java @@ -24,7 +24,11 @@ public class PortField extends JSpinner { public PortField(int number) { setModel(new SpinnerNumberModel(number, 0, 65535, 1)); - setEditor(new JSpinner.NumberEditor(this, "#")); + setEditor(new NumberEditor(this, "#")); + } + + public void setEditable(boolean value) { + ((NumberEditor)getEditor()).getTextField().setEditable(value); } public void setNumber(int number) { diff --git a/resources-en/src/messages/DebuggerBundle.properties b/resources-en/src/messages/DebuggerBundle.properties index d6a5b7adbf83..0d8d27641362 100644 --- a/resources-en/src/messages/DebuggerBundle.properties +++ b/resources-en/src/messages/DebuggerBundle.properties @@ -424,7 +424,7 @@ label.breakpoint.properties.panel.group.actions=Actions label.breakpoint.properties.panel.group.suspend.policy=Suspend policy active.tooltip.title=Evaluation of {0} active.tooltip.suggestion=Click here to view object tree -error.text.invalid.port.0=Invalid port: ''{0}'' +error.text.invalid.port.0=Invalid port: ''{0,number,#}'' error.cannot.invoke.method.in.collected.thread=Cannot invoke method: the invocation thread has been collected title.smart.step.popup=Method to Step Into action.show.watches.description=Shows or hides 'watches' pane