From 5361162addd21530d48f2be5ed1bc0d6f8f10f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Tue, 20 Aug 2024 16:56:30 +0200 Subject: [PATCH] OpenFromClipboardAction: catch NumberFormatException #472 https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/472 --- .../ui/actions/OpenFromClipboardAction.java | 146 +++++++++--------- 1 file changed, 75 insertions(+), 71 deletions(-) diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenFromClipboardAction.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenFromClipboardAction.java index ef23e0ef08..4dbacfa240 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenFromClipboardAction.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenFromClipboardAction.java @@ -304,78 +304,82 @@ private static void handleSingleLineInput(String inputText) { * @throws InterruptedException if canceled by the user */ public static int getJavaElementMatches(String inputText, List matches) throws InterruptedException { - String s = inputText.trim(); - switch (getMatchingPattern(s)) { - case JAVA_FILE_LINE: { - int index = s.indexOf(':'); - String typeName = s.substring(0, index); - typeName = s.substring(0, typeName.indexOf(".java")); //$NON-NLS-1$ - String lineNumber = s.substring(index + 1, s.length()); - lineNumber = lineNumber.trim(); - int line = Integer.parseInt(lineNumber); - getTypeMatches(typeName, matches); - return line; - } - case JAVA_FILE: { - String typeName = s.substring(0, s.indexOf(".java")); //$NON-NLS-1$ - getTypeMatches(typeName, matches); - return -1; - } - case TYPE_LINE: { - int index = s.indexOf(':'); - String typeName = s.substring(0, index); - typeName = typeName.trim(); - String lineNumber = s.substring(index + 1, s.length()); - lineNumber = lineNumber.trim(); - int line = Integer.parseInt(lineNumber); - getTypeMatches(typeName, matches); - return line; - } - case STACK_TRACE_LINE: { - int index1 = s.lastIndexOf('('); - int index2 = s.lastIndexOf(')'); - String typeLine = s.substring(index1 + 1, index2).trim(); - int index = typeLine.indexOf(':'); - String lineNumber = typeLine.substring(index + 1, typeLine.length()).trim(); - int line = Integer.parseInt(lineNumber); - - Pattern pattern = Pattern.compile(STACK_TRACE_QUALIFIED_LINE_PATTERN); - Matcher matcher = pattern.matcher(s); - if (matcher.find()) { - String qualifiedName = matcher.group(1); - index = qualifiedName.lastIndexOf('.'); - qualifiedName = qualifiedName.substring(0, index); - getTypeMatches(qualifiedName, matches); - } else { - String typeName = typeLine.substring(0, index); - typeName = typeLine.substring(0, typeName.indexOf(".java")); //$NON-NLS-1$ - getTypeMatches(typeName, matches); + try { + String s = inputText.trim(); + switch (getMatchingPattern(s)) { + case JAVA_FILE_LINE: { + int index = s.indexOf(':'); + String typeName = s.substring(0, index); + typeName = s.substring(0, typeName.indexOf(".java")); //$NON-NLS-1$ + String lineNumber = s.substring(index + 1, s.length()); + lineNumber = lineNumber.trim(); + int line = Integer.parseInt(lineNumber); + getTypeMatches(typeName, matches); + return line; + } + case JAVA_FILE: { + String typeName = s.substring(0, s.indexOf(".java")); //$NON-NLS-1$ + getTypeMatches(typeName, matches); + return -1; + } + case TYPE_LINE: { + int index = s.indexOf(':'); + String typeName = s.substring(0, index); + typeName = typeName.trim(); + String lineNumber = s.substring(index + 1, s.length()); + lineNumber = lineNumber.trim(); + int line = Integer.parseInt(lineNumber); + getTypeMatches(typeName, matches); + return line; + } + case STACK_TRACE_LINE: { + int index1 = s.lastIndexOf('('); + int index2 = s.lastIndexOf(')'); + String typeLine = s.substring(index1 + 1, index2).trim(); + int index = typeLine.indexOf(':'); + String lineNumber = typeLine.substring(index + 1, typeLine.length()).trim(); + int line = Integer.parseInt(lineNumber); + + Pattern pattern = Pattern.compile(STACK_TRACE_QUALIFIED_LINE_PATTERN); + Matcher matcher = pattern.matcher(s); + if (matcher.find()) { + String qualifiedName = matcher.group(1); + index = qualifiedName.lastIndexOf('.'); + qualifiedName = qualifiedName.substring(0, index); + getTypeMatches(qualifiedName, matches); + } else { + String typeName = typeLine.substring(0, index); + typeName = typeLine.substring(0, typeName.indexOf(".java")); //$NON-NLS-1$ + getTypeMatches(typeName, matches); + } + return line; + } + case METHOD: { + getMethodMatches(s, matches); + return -1; + } + case STACK: { + int index = s.indexOf(')'); + String method = s.substring(0, index + 1); + index = s.indexOf(':'); + String lineNumber = s.substring(index + 1).trim(); + int line = Integer.parseInt(lineNumber); + getMethodMatches(method, matches); + return line; + } + case MEMBER: + getMemberMatches(s.replace('#', '.'), matches); + return -1; + case METHOD_JAVADOC_REFERENCE: + getMethodMatches(s.replace('#', '.'), matches); + return -1; + case QUALIFIED_NAME: + getNameMatches(s, matches); + return -1; + default: + return -1; } - return line; - } - case METHOD: { - getMethodMatches(s, matches); - return -1; - } - case STACK: { - int index = s.indexOf(')'); - String method = s.substring(0, index + 1); - index = s.indexOf(':'); - String lineNumber = s.substring(index + 1).trim(); - int line = Integer.parseInt(lineNumber); - getMethodMatches(method, matches); - return line; - } - case MEMBER: - getMemberMatches(s.replace('#', '.'), matches); - return -1; - case METHOD_JAVADOC_REFERENCE: - getMethodMatches(s.replace('#', '.'), matches); - return -1; - case QUALIFIED_NAME: - getNameMatches(s, matches); - return -1; - default: + } catch (NumberFormatException e) { return -1; } }