<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hi everyone, the summary of this issue is that it seems like java.security.BasicPermission.</span><span style="font-family:arial,sans-serif;font-size:13px">implies() executes a useless check that duplicates the functionality provided by java.lang.String.startsWith().</span><span style="font-family:arial,sans-serif;font-size:13px"> </span><div style="font-family:arial,sans-serif;font-size:13px">
<br><div>Below is a jdk7 code for java.security.BasicPermission.implies() method with the lines of interest highlighted in bold:<div><br></div><div><div>public boolean implies(Permission p) {</div><div> if ((p == null) || (p.getClass() != getClass()))</div>
<div> return false;</div><div><br></div><div> BasicPermission that = (BasicPermission) p;</div><div><br></div><div> if (this.wildcard) {</div><div> if (that.wildcard) {</div><div> // one wildcard can imply another</div>
<div> return that.path.startsWith(path);</div><div> } else {</div><div> <b>// make sure ap.path is longer so a.b.* doesn't imply a.b</b></div><div><b> return (that.path.length() > this.path.length()) &&</b></div>
<div><b> that.path.startsWith(this.path);</b></div><div> }</div><div> } else {</div><div> if (that.wildcard) {</div><div> // a non-wildcard can't imply a wildcard</div>
<div> return false;</div><div> }</div><div> else {</div><div> return this.path.equals(that.path);</div><div> }</div><div> }</div><div> }</div></div>
</div><div><br></div><div>As the highlighted comment states, the length comparison check is performed in order to prevent such cases where "a.b.*" would imply "a.b". But the contract for java.lang.String.startsWith() is such that if the prefix length is greater than the string length than that test will fail. So it seems like java.security.BasicPermission.implies() tries to duplicate the check that is performed by java.lang.String.startswith() out of the box. </div>
</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Regards,</div><div style="font-family:arial,sans-serif;font-size:13px">Alex Yursha</div></div>