Skip to content

Commit

Permalink
[CBRD-25298] trim class and method names of the target method (#5104)
Browse files Browse the repository at this point in the history
* (1) trim the class name and the method name before search for the method by reflection
(2) use familiar type names of parameter types in the error messages of NoSuchMethod

* rewrite code without the Java 8 Stream feature
  • Loading branch information
hyunikn authored Apr 11, 2024
1 parent cfaaeaa commit c249ff0
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/jsp/com/cubrid/jsp/TargetMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public TargetMethod(String signature) throws Exception {
int nameStart = signature.substring(0, argStart).lastIndexOf('.') + 1;

if (signature.charAt(0) == '\'') {
className = signature.substring(1, nameStart - 1);
className = signature.substring(1, nameStart - 1).trim();
} else {
className = signature.substring(0, nameStart - 1);
className = signature.substring(0, nameStart - 1).trim();
}

methodName = signature.substring(nameStart, argStart - 1);
methodName = signature.substring(nameStart, argStart - 1).trim();
String args = signature.substring(argStart, argEnd);
argsTypes = classesFor(args);
}
Expand Down Expand Up @@ -201,14 +201,32 @@ private static void initdescriptorMap() {
descriptorMap.put("double", "D");
}

private static final String[] DUMMY_STRING_ARRAY = new String[0];

public Method getMethod()
throws SecurityException, NoSuchMethodException, ClassNotFoundException {
Class<?> c = getClass(className);
if (c == null) {
throw new ClassNotFoundException (className);
throw new ClassNotFoundException(className);
}
try {
return c.getMethod(methodName, argsTypes);
} catch (NoSuchMethodException e) {
String argsTypeNames;
int len = argsTypes.length;
if (len > 0) {
String[] arr = new String[len];
for (int i = 0; i < len; i++) {
arr[i] = argsTypes[i].getTypeName();
}
argsTypeNames = String.join(", ", arr);
} else {
argsTypeNames = "";
}

throw new NoSuchMethodException(
String.format("%s.%s(%s)", className, methodName, argsTypeNames));
}
Method m = c.getMethod(methodName, argsTypes);
return m;
}

public Class<?>[] getArgsTypes() {
Expand Down

0 comments on commit c249ff0

Please sign in to comment.