vlsi commented on code in PR #6441: URL: https://github.com/apache/jmeter/pull/6441#discussion_r2009614625
########## src/core/src/main/java/org/apache/jmeter/util/BeanShellInterpreter.java: ########## @@ -148,65 +100,111 @@ private void init() throws ClassNotFoundException { /** * Resets the BeanShell interpreter. - * - * @throws ClassNotFoundException if interpreter cannot be instantiated */ - public void reset() throws ClassNotFoundException { + public void reset() { init(); } - private Object bshInvoke(Method m, Object[] o, boolean shouldLog) throws JMeterException { + public Object eval(String s) throws JMeterException { Object r = null; - final String errorString = "Error invoking bsh method: "; try { - r = m.invoke(bshInstance, o); - } catch (IllegalArgumentException | IllegalAccessException e) { // Programming error - final String message = errorString + m.getName(); - log.error(message); - throw new JMeterError(message, e); - } catch (InvocationTargetException e) { // Can occur at run-time - // could be caused by the bsh Exceptions: - // EvalError, ParseException or TargetError - String message = errorString + m.getName(); + r = bshInstance.eval(s); + } catch (EvalError e) { + String message = String.format(BSH_ERROR_TEMPLATE, "eval"); Throwable cause = e.getCause(); if (cause != null) { message += "\t" + cause.getLocalizedMessage(); } - - if (shouldLog) { - log.error(message); - } + log.error(message); throw new JMeterException(message, e); } return r; } - public Object eval(String s) throws JMeterException { - return bshInvoke(bshEval, new Object[] { s }, true); - } - public Object evalNoLog(String s) throws JMeterException { - return bshInvoke(bshEval, new Object[] { s }, false); + Object r = null; + try { + r = bshInstance.eval(s); + } catch (EvalError e) { + String message = String.format(BSH_ERROR_TEMPLATE, "eval"); + Throwable cause = e.getCause(); + if (cause != null) { + message += "\t" + cause.getLocalizedMessage(); + } + throw new JMeterException(message, e); + } + return r; Review Comment: Could you factor out the dupilcated error handling? ########## src/core/src/main/java/org/apache/jmeter/util/BeanShellInterpreter.java: ########## @@ -148,65 +100,111 @@ private void init() throws ClassNotFoundException { /** * Resets the BeanShell interpreter. - * - * @throws ClassNotFoundException if interpreter cannot be instantiated */ - public void reset() throws ClassNotFoundException { + public void reset() { init(); } - private Object bshInvoke(Method m, Object[] o, boolean shouldLog) throws JMeterException { + public Object eval(String s) throws JMeterException { Object r = null; - final String errorString = "Error invoking bsh method: "; try { - r = m.invoke(bshInstance, o); - } catch (IllegalArgumentException | IllegalAccessException e) { // Programming error - final String message = errorString + m.getName(); - log.error(message); - throw new JMeterError(message, e); - } catch (InvocationTargetException e) { // Can occur at run-time - // could be caused by the bsh Exceptions: - // EvalError, ParseException or TargetError - String message = errorString + m.getName(); + r = bshInstance.eval(s); + } catch (EvalError e) { + String message = String.format(BSH_ERROR_TEMPLATE, "eval"); Throwable cause = e.getCause(); if (cause != null) { message += "\t" + cause.getLocalizedMessage(); } - - if (shouldLog) { - log.error(message); - } + log.error(message); throw new JMeterException(message, e); } return r; } - public Object eval(String s) throws JMeterException { - return bshInvoke(bshEval, new Object[] { s }, true); - } - public Object evalNoLog(String s) throws JMeterException { - return bshInvoke(bshEval, new Object[] { s }, false); + Object r = null; + try { + r = bshInstance.eval(s); + } catch (EvalError e) { + String message = String.format(BSH_ERROR_TEMPLATE, "eval"); + Throwable cause = e.getCause(); + if (cause != null) { + message += "\t" + cause.getLocalizedMessage(); + } + throw new JMeterException(message, e); + } + return r; Review Comment: Could you factor out the duplicated error handling? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@jmeter.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org