/usr/share/doc/aspectj-doc/progguide/pitfalls-infiniteLoops.html is in aspectj-doc 1.8.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Infinite loops</title><link rel="stylesheet" type="text/css" href="aspectj-docs.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="The AspectJTM Programming Guide"><link rel="up" href="pitfalls.html" title="Chapter 5. Pitfalls"><link rel="prev" href="pitfalls.html" title="Chapter 5. Pitfalls"><link rel="next" href="quick.html" title="Appendix A. AspectJ Quick Reference"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Infinite loops</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="pitfalls.html">Prev</a> </td><th width="60%" align="center">Chapter 5. Pitfalls</th><td width="20%" align="right"> <a accesskey="n" href="quick.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="pitfalls-infiniteLoops"></a>Infinite loops</h2></div></div></div><p>
Here is a Java program with peculiar behavior
</p><pre class="programlisting">
public class Main {
public static void main(String[] args) {
foo();
System.out.println("done with call to foo");
}
static void foo() {
try {
foo();
} finally {
foo();
}
}
}
</pre><p>
This program will never reach the println call, but when it aborts
may have no stack trace.
</p><p>
This silence is caused by multiple StackOverflowExceptions. First
the infinite loop in the body of the method generates one, which the
finally clause tries to handle. But this finally clause also
generates an infinite loop which the current JVMs can't handle
gracefully leading to the completely silent abort.
</p><p>
The following short aspect will also generate this behavior:
</p><pre class="programlisting">
aspect A {
before(): call(* *(..)) { System.out.println("before"); }
after(): call(* *(..)) { System.out.println("after"); }
}
</pre><p>
Why? Because the call to println is also a call matched by the
pointcut <code class="literal">call (* *(..))</code>. We get no output because
we used simple after() advice. If the aspect were changed to
</p><pre class="programlisting">
aspect A {
before(): call(* *(..)) { System.out.println("before"); }
after() returning: call(* *(..)) { System.out.println("after"); }
}
</pre><p>
Then at least a StackOverflowException with a stack trace would be
seen. In both cases, though, the overall problem is advice applying
within its own body.
</p><p>
There's a simple idiom to use if you ever have a worry that your
advice might apply in this way. Just restrict the advice from occurring in
join points caused within the aspect. So:
</p><pre class="programlisting">
aspect A {
before(): call(* *(..)) && !within(A) { System.out.println("before"); }
after() returning: call(* *(..)) && !within(A) { System.out.println("after"); }
}
</pre><p>
Other solutions might be to more closely restrict the pointcut in
other ways, for example:
</p><pre class="programlisting">
aspect A {
before(): call(* MyObject.*(..)) { System.out.println("before"); }
after() returning: call(* MyObject.*(..)) { System.out.println("after"); }
}
</pre><p>
The moral of the story is that unrestricted generic pointcuts can
pick out more join points than intended.
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="pitfalls.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="pitfalls.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="quick.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 5. Pitfalls </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Appendix A. AspectJ Quick Reference</td></tr></table></div></body></html>
|