Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] TypePatternsAspect.aj:5::0 does not match because declaring type is java.io.Reader, if match desired use target(org.apache.commons.io.input.NullReader) [Xlint:unmatchedSuperTypeInCall]

Hi Mikael.

You see a bit more if you change your advice like this:

  before() : read() {
    System.out.println(thisJoinPoint);
    System.out.println("  Caller = " + thisEnclosingJoinPointStaticPart);
  }

With this kind of LTW configuration

<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
  <aspects>
    <aspect name="de.scrum_master.aspect.TypePatternsAspect" />
  </aspects>
  <weaver options="-verbose -showWeaveInfo">
  </weaver>
</aspectj>

and this main class (no TestNG here)

package de.scrum_master.app;

import java.io.IOException;
import org.apache.commons.io.input.NullReader;

public class Application {
  public static void main(String[] args) throws IOException {
    NullReader nullReader = new NullReader(10);
    nullReader.read();
    char[] chars ={ 'a', 'b', 'c', 'd', 'e' };
    nullReader.read(chars);
    nullReader.close();
  }
}

I get this console log:

[AppClassLoader@18b4aac2] info AspectJ Weaver Version DEVELOPMENT built on Monday Oct 30, 2017 at 17:23:54 GMT
[AppClassLoader@18b4aac2] info register classloader sun.misc.Launcher$AppClassLoader@18b4aac2
[AppClassLoader@18b4aac2] info using configuration /C:/Users/alexa/Documents/java-src/AJ_ML_CommonsIO/bin/META-INF/aop-ajc.xml
[AppClassLoader@18b4aac2] info register aspect de.scrum_master.aspect.TypePatternsAspect
[AppClassLoader@18b4aac2] info processing reweavable type de.scrum_master.app.Application: de\scrum_master\app\Application.java
[AppClassLoader@18b4aac2] info successfully verified type de.scrum_master.aspect.TypePatternsAspect exists.  Originates from de\scrum_master\aspect\C:\Users\alexa\Documents\java-src\AJ_ML_CommonsIO\src\de\scrum_master\aspect\TypePatternsAspect.aj
[AppClassLoader@18b4aac2] weaveinfo Join point 'method-call(int org.apache.commons.io.input.NullReader.read())' in Type 'de.scrum_master.app.Application' (Application.java:9) advised by before advice from 'de.scrum_master.aspect.TypePatternsAspect' (TypePatternsAspect.aj:6)
[AppClassLoader@18b4aac2] weaveinfo Join point 'method-call(int org.apache.commons.io.input.NullReader.read(char[]))' in Type 'de.scrum_master.app.Application' (Application.java:11) advised by before advice from 'de.scrum_master.aspect.TypePatternsAspect' (TypePatternsAspect.aj:6)
[AppClassLoader@18b4aac2] weaveinfo Join point 'method-call(int org.apache.commons.io.input.NullReader.read(char[], int, int))' in Type 'org.apache.commons.io.input.NullReader' (NullReader.java:194) advised by before advice from 'de.scrum_master.aspect.TypePatternsAspect' (TypePatternsAspect.aj:6)
[AppClassLoader@18b4aac2] info processing reweavable type de.scrum_master.aspect.TypePatternsAspect: de\scrum_master\aspect\TypePatternsAspect.aj
call(int org.apache.commons.io.input.NullReader.read())
  Caller = execution(void de.scrum_master.app.Application.main(String[]))
call(int org.apache.commons.io.input.NullReader.read(char[]))
  Caller = execution(void de.scrum_master.app.Application.main(String[]))
call(int org.apache.commons.io.input.NullReader.read(char[], int, int))
  Caller = execution(int org.apache.commons.io.input.NullReader.read(char[]))

So basically I can reproduce your situation with regard to the program's log output. As you can see, the first two logs come from your own program, the third one comes from Commons-IO, indeed, because NullReader.read(char[])) calls NullReader.read(char[], int, int)).

When running your test directly via LTW configuration and TestNG (because the Eclipse plugin did not install correctly on my machine and I have never used TestNG before), it looks like this:

package de.scrum_master.app;

import java.io.IOException;

import org.apache.commons.io.input.NullReader;
import org.testng.annotations.Test;

import com.beust.testng.TestNG;

public class Example4 {
  @Test
  public void testCallToReadMethods() throws IOException {
    NullReader nullReader = new NullReader(10);
    nullReader.read();
    char[] chars = { 'a', 'b', 'c', 'd', 'e' };
    nullReader.read(chars);
    nullReader.close();
  }

  public static void main(String[] args) throws ClassNotFoundException {
    TestNG test = new TestNG();
    test.setTestClasses(new Class[] { Example4.class });
    test.run();
  }
}

Log output:

[AppClassLoader@18b4aac2] info AspectJ Weaver Version DEVELOPMENT built on Monday Oct 30, 2017 at 17:23:54 GMT
[AppClassLoader@18b4aac2] info register classloader sun.misc.Launcher$AppClassLoader@18b4aac2
[AppClassLoader@18b4aac2] info using configuration /C:/Users/alexa/Documents/java-src/AJ_ML_CommonsIO/bin/META-INF/aop-ajc.xml
[AppClassLoader@18b4aac2] info register aspect de.scrum_master.aspect.TypePatternsAspect
[AppClassLoader@18b4aac2] info processing reweavable type de.scrum_master.app.Example4: de\scrum_master\app\Example4.java
[AppClassLoader@18b4aac2] info successfully verified type de.scrum_master.aspect.TypePatternsAspect exists.  Originates from de\scrum_master\aspect\C:\Users\alexa\Documents\java-src\AJ_ML_CommonsIO\src\de\scrum_master\aspect\TypePatternsAspect.aj
[AppClassLoader@18b4aac2] weaveinfo Join point 'method-call(int org.apache.commons.io.input.NullReader.read())' in Type 'de.scrum_master.app.Example4' (Example4.java:14) advised by before advice from 'de.scrum_master.aspect.TypePatternsAspect' (TypePatternsAspect.aj:6)
[AppClassLoader@18b4aac2] weaveinfo Join point 'method-call(int org.apache.commons.io.input.NullReader.read(char[]))' in Type 'de.scrum_master.app.Example4' (Example4.java:16) advised by before advice from 'de.scrum_master.aspect.TypePatternsAspect' (TypePatternsAspect.aj:6)
[AppClassLoader@18b4aac2] weaveinfo Join point 'method-call(int org.apache.commons.io.input.NullReader.read(char[], int, int))' in Type 'org.apache.commons.io.input.NullReader' (NullReader.java:194) advised by before advice from 'de.scrum_master.aspect.TypePatternsAspect' (TypePatternsAspect.aj:6)
[TestNG] Running:
  Command line suite

[AppClassLoader@18b4aac2] info processing reweavable type de.scrum_master.aspect.TypePatternsAspect: de\scrum_master\aspect\TypePatternsAspect.aj
call(int org.apache.commons.io.input.NullReader.read())
  Caller = execution(void de.scrum_master.app.Example4.testCallToReadMethods())
call(int org.apache.commons.io.input.NullReader.read(char[]))
  Caller = execution(void de.scrum_master.app.Example4.testCallToReadMethods())
call(int org.apache.commons.io.input.NullReader.read(char[], int, int))
  Caller = execution(int org.apache.commons.io.input.NullReader.read(char[]))

===============================================
Command line suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Also no strange warnings about some Gson class shaded into TestNG. It must be connected to how you run TestNG, maybe you use a package or plugin which contains Gson somehow, somewhere, or it is part of your project, a side effect of any of the other two aspects listed in your log output. I have no idea. Anyway, you can probably avoid it by excluding TestNG classes from LTW like this:

<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
    <aspects>
        <aspect name="de.scrum_master.aspect.TypePatternsAspect"/>
    </aspects>
    <weaver options="-verbose -showWeaveInfo">
        <exclude within="org.testng..*"/>
    </weaver>
</aspectj>

I hope this helps, I had to speculate a bit, not seeing your whole project.

Regards
--
Alexander Kriegisch
https://scrum-master.de
 
Mikael Petterson schrieb am 13.12.2018 14:47:
I have a testcase (TESTNG) looking like this:
 
public class Example4 {
 @Test
  public void testCallToReadMethods() throws IOException {
      NullReader nullReader = new NullReader(10);
      nullReader.read();
      char[] chars ={ 'a', 'b', 'c', 'd', 'e' };
      nullReader.read(chars);
      nullReader.close();
     
  }
}
It calls methods in apache commons-io:
 
https://commons.apache.org/proper/commons-io/javadocs/api-release/index.html
 
 
This is my simple aspect:
 
public aspect TypePatternsAspect {
   
    pointcut read(): call(* org.apache.commons.io.input.NullReader.read(..));
   
    before() : read() {
        String callingClass = thisJoinPoint.getStaticPart().getSourceLocation().getWithinType().getName();
        System.out.println("Caller "+callingClass);
    }
   
}
 
I can see that print is done 3 times:
 
 
Caller examples.Example4
Caller examples.Example4
Caller org.apache.commons.io.input.NullReader
 
Questions:
 
  1. Does this mean that one of these reader methods call another read() within NullReader?
  2. Looking at the log below I wonder:
    a) Why is AspectJ Weaver called twice?
    b) What does this warning mean:
     
    [AppClassLoader@18b4aac2] warning at examples\C:\Users\eraonel\git\java-runtime-stats\collector\src\test\java\examples\TypePatternsAspect.aj:5::0 does not match because declaring type is java.io.Reader, if match desired use target(org.apache.commons.io.input.NullReader) [Xlint:unmatchedSuperTypeInCall]
    see also: org\testng\shaded\com\google\gson\stream\JsonReader.java:1295::0

    How can I get rid of this warning?
br,
 
//mike
 
[AppClassLoader@18b4aac2] info AspectJ Weaver Version 1.9.2 built on Wednesday Oct 24, 2018 at 15:43:33 GMT
[AppClassLoader@18b4aac2] info register classloader sun.misc.Launcher$AppClassLoader@18b4aac2
[AppClassLoader@18b4aac2] info using configuration /C:/Users/eraonel/git/java-runtime-stats/collector/target/test-classes/META-INF/aop3.xml
[AppClassLoader@18b4aac2] info register aspect examples.IllegalAccessAspect
[AppClassLoader@18b4aac2] info register aspect examples.DeprecatedMethodAccessAspect
[AppClassLoader@18b4aac2] info register aspect examples.TypePatternsAspect
[RemoteTestNG] detected TestNG version 6.14.6
[ExtClassLoader@fad74ee] info AspectJ Weaver Version 1.9.2 built on Wednesday Oct 24, 2018 at 15:43:33 GMT
[ExtClassLoader@fad74ee] info register classloader sun.misc.Launcher$ExtClassLoader@fad74ee
[ExtClassLoader@fad74ee] info no configuration found. Disabling weaver for class loader sun.misc.Launcher$ExtClassLoader@fad74ee
[AppClassLoader@18b4aac2] info processing reweavable type examples.Example4: examples\Example4.java
[AppClassLoader@18b4aac2] info successfully verified type examples.TypePatternsAspect exists.  Originates from examples\C:\Users\eraonel\git\java-runtime-stats\collector\src\test\java\examples\TypePatternsAspect.aj
[AppClassLoader@18b4aac2] weaveinfo Join point 'method-call(int org.apache.commons.io.input.NullReader.read())' in Type 'examples.Example4' (Example4.java:13) advised by before advice from 'examples.TypePatternsAspect' (TypePatternsAspect.aj:7)
[AppClassLoader@18b4aac2] weaveinfo Join point 'method-call(int org.apache.commons.io.input.NullReader.read(char[]))' in Type 'examples.Example4' (Example4.java:15) advised by before advice from 'examples.TypePatternsAspect' (TypePatternsAspect.aj:7)
[AppClassLoader@18b4aac2] warning at examples\C:\Users\eraonel\git\java-runtime-stats\collector\src\test\java\examples\TypePatternsAspect.aj:5::0 does not match because declaring type is java.io.Reader, if match desired use target(org.apache.commons.io.input.NullReader) [Xlint:unmatchedSuperTypeInCall]
see also: org\testng\shaded\com\google\gson\stream\JsonReader.java:1295::0
[AppClassLoader@18b4aac2] weaveinfo Join point 'method-call(int org.apache.commons.io.input.NullReader.read(char[], int, int))' in Type 'org.apache.commons.io.input.NullReader' (NullReader.java:194) advised by before advice from 'examples.TypePatternsAspect' (TypePatternsAspect.aj:7)
[AppClassLoader@18b4aac2] info processing reweavable type examples.TypePatternsAspect: examples\TypePatternsAspect.aj
Called org.apache.commons.io.input.NullReader@4281a26f
Called org.apache.commons.io.input.NullReader@4281a26f
Called org.apache.commons.io.input.NullReader@4281a26f
[AppClassLoader@18b4aac2] warning at examples\C:\Users\eraonel\git\java-runtime-stats\collector\src\test\java\examples\TypePatternsAspect.aj:5::0 does not match because declaring type is java.io.Reader, if match desired use target(org.apache.commons.io.input.NullReader) [Xlint:unmatchedSuperTypeInCall]
see also: org\testng\reporters\FileStringBuffer.java:94::0

 

 


Back to the top