<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Constructor Execution Pointcut Causing ArrayOutOfBounds
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/nwhitehead">Nicholas Whitehead</a> in <i>JBoss AOP</i> - <a href="http://community.jboss.org/message/564607#564607">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hello;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Java 1.6</p><p>JBoss AOP 2.1.8.GA</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have been wrestling with this for a while now. I have defined a pointcut for the execution of private constructors on classes annotated with <strong>@EntityTXAttribute</strong>. However, while the weaving is going on, an ArrayOutOfBounds exception occurs, and having run it through the debugger, it seems to make sense why, but I am noit sure how to fix it.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The pointcut expression is:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong style="font-family: courier new,courier; "> execution(public !static * @entitypojo.annotations.EntityTXAttribute-&gt;*(..)) <br/></strong></p><p><strong style="font-family: courier new,courier; "> OR execution(protected !static * @entitypojo.annotations.EntityTXAttribute-&gt;*(..)) <br/></strong></p><p><strong style="font-family: courier new,courier; "> OR execution(private @entitypojo.annotations.EntityTXAttribute-&gt;new(..)) </strong></p><p><strong><br/></strong></p><p>or <em><strong>all public non-static methods in annotated classes, and all private constructors</strong>.</em></p><p>The method invocation interceptions work perfectly, btw.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My bean has 2 ctors, on parameterized and one not. I set a debugger break point on org.jboss.aop.Advisor line 1870 where the error occurs.</p><p>What I see is this:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The instance has an array called <strong>constructors</strong> which has 4 constructors in it, 2 of which I defined and 2 of which appear to be synthetic. They broadly look like this:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ol><li>private Bean()&#160;&#160; (mine)</li><li>Bean(javassist.runtime.Inner)&#160;&#160; (synthetic)</li><li>private Bean(String, String)&#160;&#160;&#160;&#160; (mine)</li><li>Bean(String, String, javassist.runtime.Inner)&#160;&#160; (synthetic)</li></ol><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>However, the array of <strong>constructorInfos</strong> only has 2 entries in it which are</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ol><li>private Bean()&#160;&#160; (mine)</li><li>private Bean(String, String)&#160;&#160;&#160;&#160; (mine)</li></ol><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The method code looks like this:</p><p><span style="font-family: courier new,courier;"><br/></span></p><p><strong style="font-family: courier new,courier; ">protected void resolveConstructorPointcut(AdviceBinding binding)<br/>&#160;&#160; {<br/>&#160;&#160;&#160;&#160;&#160; for (int i = 0; i &lt; constructors.length; i++)<br/>&#160;&#160;&#160;&#160;&#160; {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Constructor&lt;?&gt; constructor = constructors[i];<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (binding.getPointcut().matchesExecution(this, constructor))<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (AspectManager.verbose) logger.debug("constructor matched binding: " + constructor);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; adviceBindings.add(binding);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; binding.addAdvisor(this);</strong></p><p><strong style="font-family: courier new,courier; "> <span style="color: #ff0000;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // this is where the error occurs. Line 1870.</span><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #ff0000;">pointcutResolved(constructorInfos[i], binding, new ConstructorJoinpoint(constructor));</span><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // if we must keep track of deprecated fields and the field is already initialized<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (AspectManager.maintainAdvisorMethodInterceptors &amp;&amp; constructorInterceptors != null)<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; constructorInterceptors[i] = constructorInfos[i].getInterceptors();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160; }</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>This code assumes the number of <strong>constructorInfos</strong> is at least the same as the number of <strong>constructors</strong>, but since it is not, it throws an array out of bounds exception.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Am I doing something wrong here, or is it a bug ?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Much appreciated.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>//Nicholas</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/564607#564607">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss AOP at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2027">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>