[ http://thecla.homeftp.net:8380/jira/browse/BPM-136?page=history ] Work on BPM-136 started by Chad Brandon
> ClassCastException caused by generated class PatternMatchingExceptionHandler > ---------------------------------------------------------------------------- > > Key: BPM-136 > URL: http://thecla.homeftp.net:8380/jira/browse/BPM-136 > Project: Bpm4Struts Cartridge > Type: Bug > Environment: AndroMDA RC1 > Reporter: Johnny Macchione > Assignee: Chad Brandon > > > The generated > org.andromda.presentation.bpm4struts.PatternMatchingExceptionHandler class > throws ClassCastException when handling exceptions that have a root cause > which isn't a java.lang.Exception. > For exemple, when a class on which the web application is dependent can't be > found, I get the following exception in the stack trace: > java.lang.ClassCastException: java.lang.NoClassDefFoundError > This hides the real exception message which is actually: > java.lang.NoClassDefFoundError: javax/transaction/TransactionManager > The ClassCastException is caused by the following statement: > exception = (Exception) this.findRootCause(exception); > Reason: > The root cause of an Exception can be any Throwable => we can't assume it is > always an Exception. > I could get the error message by changing the generated file manually (see > code fragment hereafter), but it would be easier to change the method > signature to throw Throwable instead of Exception: > Generated code: > public String handleException(Exception exception) throws Exception > { > exception = (Exception)this.findRootCause(exception); > String matched = null; > if (exception != null && exception.getMessage() != null) > { > Matcher matcher = compiledPattern.matcher( > exception.getMessage().replaceAll("[\\s]+", " ")); > try > { > if (matcher.matches()) > { > matched = matcher.group(3); > } > if (matched == null) > { > throw exception; > } > } > catch (IllegalStateException ex) > { > // no match was found rethrow the exception > throw exception; > } > return matched; > } > throw exception; > } > Manually edited code: > public String handleException(Exception exception) throws Exception > { > final Throwable t = this.findRootCause(exception); > > if (t != null && t.getMessage() != null) > { > String matched = null; > Matcher matcher = compiledPattern.matcher( > t.getMessage().replaceAll("[\\s]+", " ")); > try > { > if (matcher.matches()) > { > matched = matcher.group(3); > } > } > catch (IllegalStateException ex) > { > // no match was found rethrow the exception > } > if (matched != null) > { > return matched; > } > } > if (t instanceof Exception) { > throw (Exception) t; > } else if (t instanceof Error) { > throw (Error) t; > } else { > throw new Exception(t); > } > } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://thecla.homeftp.net:8380/jira/secure/Administrators.jspa - If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Andromda-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/andromda-devel
