title: Two Pointcuts for two methods with the same name but different arguments
body: <p>Hei.</p>
  
  <p>I'm writing an @Aspect for the logging of my persistence layer.</p>
  
  <p>First some code which may show the error to an experienced developer ;)</p>
  
  <pre><code>/** Interface of the class to observe. */
  public interface PersistenceService {
  
      public Serializable save(Serializable serializable);
  
      public List&lt;Serializable&gt; save(List&lt;Serializable&gt; list)
  }
  
  /** Actual class to observe. */
  @Service
  public class PersistenceService {
  
      @Autowired
      private SomeJpaRepository rep;
  
      public Serializable save(Serializable serializable) {
          return rep.save(serializable);
      }
  
      public List&lt;Serializable&gt; save(List&lt;Serializable&gt; list) {
          return rep.save(list);
      }
  }
  </code></pre>
  
  <p>And here the Aspect:</p>
  
  <pre><code>/** The Aspect. */
  @Aspect
  @Component
  public class PersistenceService {
  
      /** A org.slf4j.Logger (using logback). */
      private final Logger logger = LoggerFactory.getLogger(getClass());
  
      /** Pointcut to define the classes to observe. */
      @Pointcut("within(de.mypckg.myproject.persistence.*.*)")
      public void inPersistanceLayer() {}
  
      /** Pointcut for the first save-method. */
      @Pointcut("execution(public * save(..)) &amp;&amp; args(serializable)")
      public void saveOperation(Serializable serializable) {}
  
      /** Pointcut for the first save-method. */
      @Pointcut("execution(public * save(..)) &amp;&amp; args(list)")
      public void saveOperation(List&lt;Serializable&gt; list) {}
  
      /** Method for the first save-method. */
      @Around("inPersistanceLayer() &amp;&amp; saveOperation(serializable)")
      public List&lt;Serializable&gt; logSave(ProceedingJoinPoint joinPoint, Serializable serializable) throws Throwable {
  
          // log some stuff
          Object saved = joinPoint.proceed();
          // log somemore stuff
      }
  
      /** Method for the second save-method. */
      @Around("inPersistanceLayer() &amp;&amp; saveOperation(list)")
      public List&lt;Serializable&gt; logSave(ProceedingJoinPoint joinPoint, List&lt;Serializable&gt; list) throws Throwable {
  
          // log some stuff
          Object saved = joinPoint.proceed();
          // log somemore stuff
      }
  }
  </code></pre>
  
  <p>If I only have one of the Pointcuts (and the method for it) it works, but if I add the second, I get the following exception:</p>
  
  <pre><code>java.lang.IllegalArgumentException: warning no match for this type name: list [Xlint:invalidAbsoluteTypeName]
  </code></pre>
  
  <p>I changed the order of the pointcuts, it's always the second in line. Any ideas on how to solve this?</p>
  
  <p><strong>Update</strong><br>
  Once I had posted the question I had an idea. I changed the Pointcuts like this:</p>
  
  <pre><code>/** The Aspect. */
  @Aspect
  @Component
  public class PersistenceService {
  
      /** A org.slf4j.Logger (using logback). */
      private final Logger logger = LoggerFactory.getLogger(getClass());
  
      /** Pointcut to define the classes to observe. */
      @Pointcut("within(de.mypckg.myproject.persistence.*.*)")
      public void inPersistanceLayer() {}
  
      /** Pointcut for the save-method. */
      @Pointcut("execution(public * save(..))")
      public void saveOperation() {}
  
      /** Pointcut for the serializable argument. */
      @Pointcut("args(serializable)")
      public void serializableArgument(Serializable serializable) {}
  
      /** Pointcut for the list argument. */
      @Pointcut("args(list)")
      public void listArgument(List&lt;Serializable&gt; list) {}
  
      /** Method for the first save-method. */
      @Around("inPersistanceLayer() &amp;&amp; saveOperation() &amp;&amp; serializableArgument(serializable)")
      public Object logSave(ProceedingJoinPoint joinPoint, Serializable serializable) throws Throwable {
  
          // log some stuff
          Object saved = joinPoint.proceed();
          // log somemore stuff
          return saved;
      }
  
      /** Method for the second save-method. */
      @Around("inPersistanceLayer() &amp;&amp; saveOperation(list) &amp;&amp; listArgument(list)")
      public Object logSave(ProceedingJoinPoint joinPoint, List&lt;Serializable&gt; list) throws Throwable {
  
          // log some stuff
          Object saved = joinPoint.proceed();
          // log somemore stuff
          return saved;
      }
  }
  </code></pre>
  
  <p>Now the exception is gone, but there is still a small issue (which is much easier to solve I guess): Since ArrayList implements Serializable both pointcuts are executed, at least in my test case where I use an ArrayList.<br>
  I will look into that and post what I find, but help is appreciated as well ;)</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>Corrected a copy paste error stated by kriegaex. Thanks!</p>
  
  <p>The return type of the methods logSave(..) is Object.</p>
  
  <p><strong>Update 3</strong></p>
  
  <p>I changed the code to just using one pointcut and one method and check with instanceof like kriegaex proposed.</p>
  
  <pre><code>/** The Aspect. */
  @Aspect
  @Component
  public class PersistenceService {
  
      /** A org.slf4j.Logger (using logback). */
      private final Logger logger = LoggerFactory.getLogger(getClass());
  
      /** Pointcut to define the classes to observe. */
      @Pointcut("within(de.mypckg.myproject.persistence.*.*)")
      public void inPersistanceLayer() {}
  
      /** Pointcut for the save-method. */
      @Pointcut("execution(public * save(*)) &amp;&amp; args(serializable)")
      public void saveOperation(Serializable serializable) {}
  
      /** Method for the first save-method. */
      @Around("inPersistanceLayer() &amp;&amp; saveOperation() &amp;&amp; serializableArgument(serializable)")
      public Serializable logSave(ProceedingJoinPoint joinPoint, Serializable serializable) throws Throwable {
  
          // log some stuff
          Serializable saved = (Serializable) joinPoint.proceed();
  
          if (saved instanceof List&lt;?&gt;) {
              List&lt;?&gt; savedList = (List&lt;?&gt;) saved;
              // log somemore stuff with a List
          } else {
              // log somemore stuff
          }
          return saved;
      }
  }
  </code></pre>
  
  <p>I still wonder why it didn't work the other way.</p>