Skip to content

Commit 7d2a805

Browse files
LZarubaolamy
authored andcommitted
GH-74 Unsupported Type as a return type or field is not recognized (#75)
* GH-74 Unsupported Type as a return type or field is not recognized Added tests and samples to verify the problem and solution Added fields validation Added method return type validation * GH-74 Unsupported Type as a return type or field is not recognized Updated examples to be Java 7 compatible * GH-74 Unsupported Type as a return type or field is not recognized Moved tests into IT Bumped commons-lang3 to prevent java11 failure Bumped maven invoker plugin to fix issue where IT builds were not executed on java13
1 parent 524e402 commit 7d2a805

File tree

13 files changed

+405
-81
lines changed

13 files changed

+405
-81
lines changed

animal-sniffer-maven-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<dependency>
7878
<groupId>org.apache.commons</groupId>
7979
<artifactId>commons-lang3</artifactId>
80-
<version>3.7</version>
80+
<version>3.9</version>
8181
</dependency>
8282
<dependency>
8383
<groupId>org.apache.maven.shared</groupId>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.buildResult=failure
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
The MIT License
4+
5+
Copyright (c) 2009 codehaus.org.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
-->
25+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
27+
<modelVersion>4.0.0</modelVersion>
28+
29+
<parent>
30+
<groupId>org.codehaus.mojo.its</groupId>
31+
<artifactId>animal-sniffer-parent</artifactId>
32+
<version>1.0-SNAPSHOT</version>
33+
</parent>
34+
35+
<groupId>localdomain.localhost</groupId>
36+
<artifactId>real-test</artifactId>
37+
<version>1.0-SNAPSHOT</version>
38+
<packaging>jar</packaging>
39+
40+
<name>github-74-1</name>
41+
42+
<build>
43+
<pluginManagement>
44+
<plugins>
45+
<plugin>
46+
<artifactId>maven-clean-plugin</artifactId>
47+
<version>2.2</version>
48+
</plugin>
49+
<plugin>
50+
<artifactId>maven-compiler-plugin</artifactId>
51+
<version>3.5.1</version>
52+
<configuration>
53+
<source>@mojo.java.target@</source>
54+
<target>@mojo.java.target@</target>
55+
</configuration>
56+
</plugin>
57+
<plugin>
58+
<artifactId>maven-surefire-plugin</artifactId>
59+
<version>2.4.2</version>
60+
</plugin>
61+
</plugins>
62+
</pluginManagement>
63+
<plugins>
64+
<plugin>
65+
<artifactId>maven-compiler-plugin</artifactId>
66+
<configuration>
67+
<source>1.8</source>
68+
<target>1.8</target>
69+
</configuration>
70+
</plugin>
71+
<plugin>
72+
<groupId>${pluginGroupId}</groupId>
73+
<artifactId>${pluginArtifactId}</artifactId>
74+
<version>${pluginVersion}</version>
75+
<executions>
76+
<execution>
77+
<phase>test</phase>
78+
<goals>
79+
<goal>check</goal>
80+
</goals>
81+
<configuration>
82+
<signature>
83+
<groupId>org.codehaus.mojo.signature</groupId>
84+
<artifactId>java16</artifactId>
85+
<version>1.1</version>
86+
</signature>
87+
</configuration>
88+
</execution>
89+
</executions>
90+
</plugin>
91+
</plugins>
92+
</build>
93+
<properties>
94+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
95+
<project.build.outputEncoding>UTF-8</project.build.outputEncoding>
96+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
97+
<pluginGroupId>@project.groupId@</pluginGroupId>
98+
<pluginArtifactId>@project.artifactId@</pluginArtifactId>
99+
<pluginVersion>@project.version@</pluginVersion>
100+
</properties>
101+
102+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package localhost;
2+
3+
import java.nio.file.Paths;
4+
5+
/**
6+
* @author Lukas Zaruba, lukas.zaruba@lundegaard.eu, 2019
7+
*/
8+
public class IllegalFieldSample {
9+
10+
private String stringField;
11+
private Paths pathsField;
12+
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package localhost;
2+
3+
import java.nio.file.Path;
4+
5+
/**
6+
* @author Lukas Zaruba, lukas.zaruba@lundegaard.eu, 2019
7+
*/
8+
public class IllegalFieldWithAccessorsSample {
9+
10+
private String stringField;
11+
private Path pathField;
12+
13+
public String getStringField() {
14+
return stringField;
15+
}
16+
17+
public void setStringField(String stringField) {
18+
this.stringField = stringField;
19+
}
20+
21+
public Path getPathField() {
22+
return pathField;
23+
}
24+
25+
public void setPathField(Path pathField) {
26+
this.pathField = pathField;
27+
}
28+
29+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package localhost;
2+
3+
import java.nio.file.Path;
4+
5+
/**
6+
* @author Lukas Zaruba, lukas.zaruba@lundegaard.eu, 2019
7+
*/
8+
public class IllegalFieldWithManipulationSample {
9+
10+
private String stringField;
11+
private Path pathField;
12+
13+
public Path getPathField() {
14+
return pathField;
15+
}
16+
17+
public void setPathField(Path pathField) {
18+
this.pathField = pathField.resolve("other");
19+
}
20+
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package localhost;
2+
3+
import java.nio.file.Path;
4+
5+
/**
6+
* @author Lukas Zaruba, lukas.zaruba@lundegaard.eu, 2019
7+
*/
8+
public class IllegalTypeReturn {
9+
10+
public Path localDateTime() {
11+
return null;
12+
}
13+
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
File log = new File(basedir, 'build.log')
2+
3+
assert log.text.contains( 'IllegalTypeReturn.java:11: Undefined reference: java.nio.file.Path' )
4+
assert log.text.contains( 'IllegalFieldWithManipulationSample.java: Undefined reference: java.nio.file.Path' )
5+
assert log.text.contains( 'IllegalFieldWithManipulationSample.java:14: Undefined reference: java.nio.file.Path' )
6+
assert log.text.contains( 'IllegalFieldWithManipulationSample.java:18: Undefined reference: java.nio.file.Path' )
7+
assert log.text.contains( 'IllegalFieldWithManipulationSample.java:18: Undefined reference: java.nio.file.Path java.nio.file.Path.resolve(String)' )
8+
assert log.text.contains( 'IllegalFieldWithAccessorsSample.java: Undefined reference: java.nio.file.Path' )
9+
assert log.text.contains( 'IllegalFieldWithAccessorsSample.java:22: Undefined reference: java.nio.file.Path' )
10+
assert log.text.contains( 'IllegalFieldSample.java: Undefined reference: java.nio.file.Paths' )
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
The MIT License
4+
5+
Copyright (c) 2009 codehaus.org.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
-->
25+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
27+
<modelVersion>4.0.0</modelVersion>
28+
29+
<parent>
30+
<groupId>org.codehaus.mojo.its</groupId>
31+
<artifactId>animal-sniffer-parent</artifactId>
32+
<version>1.0-SNAPSHOT</version>
33+
</parent>
34+
35+
<groupId>localdomain.localhost</groupId>
36+
<artifactId>real-test</artifactId>
37+
<version>1.0-SNAPSHOT</version>
38+
<packaging>jar</packaging>
39+
40+
<name>github-74-2</name>
41+
42+
<build>
43+
<pluginManagement>
44+
<plugins>
45+
<plugin>
46+
<artifactId>maven-clean-plugin</artifactId>
47+
<version>2.2</version>
48+
</plugin>
49+
<plugin>
50+
<artifactId>maven-compiler-plugin</artifactId>
51+
<version>3.5.1</version>
52+
<configuration>
53+
<source>@mojo.java.target@</source>
54+
<target>@mojo.java.target@</target>
55+
</configuration>
56+
</plugin>
57+
<plugin>
58+
<artifactId>maven-surefire-plugin</artifactId>
59+
<version>2.4.2</version>
60+
</plugin>
61+
</plugins>
62+
</pluginManagement>
63+
<plugins>
64+
<plugin>
65+
<artifactId>maven-compiler-plugin</artifactId>
66+
<configuration>
67+
<source>1.8</source>
68+
<target>1.8</target>
69+
</configuration>
70+
</plugin>
71+
<plugin>
72+
<groupId>${pluginGroupId}</groupId>
73+
<artifactId>${pluginArtifactId}</artifactId>
74+
<version>${pluginVersion}</version>
75+
<executions>
76+
<execution>
77+
<phase>test</phase>
78+
<goals>
79+
<goal>check</goal>
80+
</goals>
81+
<configuration>
82+
<signature>
83+
<groupId>org.codehaus.mojo.signature</groupId>
84+
<artifactId>java16</artifactId>
85+
<version>1.1</version>
86+
</signature>
87+
</configuration>
88+
</execution>
89+
</executions>
90+
</plugin>
91+
</plugins>
92+
</build>
93+
<properties>
94+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
95+
<project.build.outputEncoding>UTF-8</project.build.outputEncoding>
96+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
97+
<pluginGroupId>@project.groupId@</pluginGroupId>
98+
<pluginArtifactId>@project.artifactId@</pluginArtifactId>
99+
<pluginVersion>@project.version@</pluginVersion>
100+
</properties>
101+
102+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.codehaus.mojo.animal_sniffer.samples;
2+
3+
/**
4+
* @author Lukas Zaruba, lukas.zaruba@lundegaard.eu, 2019
5+
*/
6+
public class FieldsOK {
7+
8+
private String niceFiled;
9+
10+
}

0 commit comments

Comments
 (0)