java.lang.IllegalArgumentException: Illegal group reference

Apache's JIRA Issue Tracker | Dominik Stadler | 3 years ago
  1. 0

    I have a unit test which shows that dollar sign and backslash cause ImageHtmlEmail to throw an Exception (unfortunately not easy to provide a complete unit test, but it should be easy to enhance one of the existing tests for ImageHtmlEmail): {quote} FileUtils.writeStringToFile(file, "<html>teststring <img title=\"$\" src=\"file://" + file.getAbsolutePath() + "\"/></html>"); sender.sendHTMLEmail(files, mailConfig, emailConfig, REPORT_DIR); {quote} It will throw the following Exception: {quote} java.lang.IllegalArgumentException: Illegal group reference at java.util.regex.Matcher.appendReplacement(Matcher.java:808) at org.apache.commons.mail.ImageHtmlEmail.replacePattern(ImageHtmlEmail.java:180) at org.apache.commons.mail.ImageHtmlEmail.buildMimeMessage(ImageHtmlEmail.java:103) at org.apache.commons.mail.Email.send(Email.java:1427) at EmailSender.sendHTMLEmail(EmailSender.java:93) at EmailSenderTest.testImageHtmlEmailDollarBackslash(EmailSenderTest.java:801) {quote} the cause is that Matcher.appendReplacement() actually treats Dollar and Backslash as special characters. From the javadoc of Matcher: {quote} * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in * the replacement string may cause the results to be different than if it * were being treated as a literal replacement string. Dollar signs may be * treated as references to captured subsequences as described above, and * backslashes are used to escape literal characters in the replacement * string. {quote} A possible fix is to replace line 180 of ImageHtmlEmail.java with the following, i.e. replace {{$}} by {{\$}} and \ by \ \ to have them properly escaped. {code} matcher.appendReplacement(stringBuffer, (matcher.group(1) + "cid:" + cid + matcher.group(3)).replace("\\", "\\\\").replace("$", "\\$")); {code}

    Apache's JIRA Issue Tracker | 3 years ago | Dominik Stadler
    java.lang.IllegalArgumentException: Illegal group reference
  2. Speed up your debug routine!

    Automated exception search integrated into your IDE

  3. 0

    java.lang.IllegalArgumentException: Illegal group reference

    GitHub | 10 months ago | yegor256
    java.lang.IllegalArgumentException: Illegal group reference
  4. 0

    An IllegalArgumentException is thrown when an h:selectOneMenu contains a '$' character. This issue has been reported before in ICE-8458. Testing with the EE 3.3.0 P02 release the exception is not thrown. Testing with the EE 3.3.0 P03, EE 4.0.0, and the ICEfaces 3 and 4 branch/trunk code shows this issue. Here is the stack trace: 25-Sep-2015 12:25:00.667 SEVERE [http-nio-8084-exec-5] com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError java.lang.IllegalArgumentException: Illegal group reference at java.util.regex.Matcher.appendReplacement(Matcher.java:808) at org.icefaces.impl.context.DOMPartialViewContext.applyBrowserChanges(DOMPartialViewContext.java:644) at org.icefaces.impl.context.DOMPartialViewContext.processPartial(DOMPartialViewContext.java:137) at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:973) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1778) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:426) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:604) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

    ICEsoft JIRA Issue Tracker | 1 year ago | Arran Mccullough
    java.lang.IllegalArgumentException: Illegal group reference

    4 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Illegal group reference

      at java.util.regex.Matcher.appendReplacement()
    2. Java RT
      Matcher.appendReplacement
      1. java.util.regex.Matcher.appendReplacement(Matcher.java:808)
      1 frame
    3. Apache Commons Email
      Email.send
      1. org.apache.commons.mail.ImageHtmlEmail.replacePattern(ImageHtmlEmail.java:180)
      2. org.apache.commons.mail.ImageHtmlEmail.buildMimeMessage(ImageHtmlEmail.java:103)
      3. org.apache.commons.mail.Email.send(Email.java:1427)
      3 frames
    4. Unknown
      EmailSenderTest.testImageHtmlEmailDollarBackslash
      1. EmailSender.sendHTMLEmail(EmailSender.java:93)
      2. EmailSenderTest.testImageHtmlEmailDollarBackslash(EmailSenderTest.java:801)
      2 frames