Skip to content

Commit

Permalink
Merge 43da67d into fbab1b4
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkravin committed Sep 1, 2014
2 parents fbab1b4 + 43da67d commit 3a0dad2
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 69 deletions.
25 changes: 25 additions & 0 deletions sevntu-checks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,31 @@
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputNoNullForCollectionReturnCheck1.java</source>
<source>sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputNoNullForCollectionReturnCheck2.java</source>
<source>sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputNoNullForCollectionReturnCheck3.java</source>
<source>sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputNoNullForCollectionReturnCheck4.java</source>
<source>sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputNoNullForCollectionReturnCheck5.java</source>
<source>sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputNoNullForCollectionReturnCheck6.java</source>
<source>sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputNoNullForCollectionReturnCheck7.java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public void testArraysNotDeep() throws Exception
{
final DefaultConfiguration checkConfig = createCheckConfig(NoNullForCollectionReturnCheck.class);
final String[] expected = {
"10: " + warningMessage,
"45: " + warningMessage,
"53: " + warningMessage,
"58: " + warningMessage,
"11: " + warningMessage,
"46: " + warningMessage,
"54: " + warningMessage,
"59: " + warningMessage,
};

verify(checkConfig, getPath("InputNoNullForCollectionReturnCheck1.java"), expected);
Expand All @@ -32,11 +32,11 @@ public void testArraysDeep() throws Exception
final DefaultConfiguration checkConfig = createCheckConfig(NoNullForCollectionReturnCheck.class);
checkConfig.addAttribute("searchThroughMethodBody", "true");
final String[] expected = {
"10: " + warningMessage,
"17: " + warningMessage,
"45: " + warningMessage,
"53: " + warningMessage,
"58: " + warningMessage,
"11: " + warningMessage,
"18: " + warningMessage,
"46: " + warningMessage,
"54: " + warningMessage,
"59: " + warningMessage,
};

verify(checkConfig, getPath("InputNoNullForCollectionReturnCheck1.java"), expected);
Expand All @@ -50,13 +50,13 @@ public void testCollections() throws Exception
checkConfig.addAttribute("collectionList", listOfCollecton);
final String[] expected = {

"5: " + warningMessage,
"15: " + warningMessage,
"25: " + warningMessage,
"35: " + warningMessage,
"45: " + warningMessage,
"55: " + warningMessage,
"65: " + warningMessage,
"7: " + warningMessage,
"17: " + warningMessage,
"27: " + warningMessage,
"37: " + warningMessage,
"47: " + warningMessage,
"57: " + warningMessage,
"67: " + warningMessage,
};

verify(checkConfig, getPath("InputNoNullForCollectionReturnCheck2.java"), expected);
Expand All @@ -67,8 +67,8 @@ public void testRevereCode() throws Exception
{
final DefaultConfiguration checkConfig = createCheckConfig(NoNullForCollectionReturnCheck.class);
final String[] expected = {
"12: " + warningMessage,
"15: " + warningMessage,
"13: " + warningMessage,
"16: " + warningMessage,
};

verify(checkConfig, getPath("InputNoNullForCollectionReturnCheck3.java"), expected);
Expand All @@ -80,8 +80,8 @@ public void testRevereCodeDeep() throws Exception
final DefaultConfiguration checkConfig = createCheckConfig(NoNullForCollectionReturnCheck.class);
checkConfig.addAttribute("searchThroughMethodBody", "true");
final String[] expected = {
"12: " + warningMessage,
"15: " + warningMessage,
"13: " + warningMessage,
"16: " + warningMessage,
};

verify(checkConfig, getPath("InputNoNullForCollectionReturnCheck3.java"), expected);
Expand All @@ -102,10 +102,10 @@ public void testInnerClasses() throws Exception
{
final DefaultConfiguration checkConfig = createCheckConfig(NoNullForCollectionReturnCheck.class);
final String[] expected = {
"16: " + warningMessage,
"24: " + warningMessage,
"26: " + warningMessage,
"38: " + warningMessage,
"17: " + warningMessage,
"25: " + warningMessage,
"27: " + warningMessage,
"39: " + warningMessage,
};

verify(checkConfig, getPath("InputNoNullForCollectionReturnCheck5.java"), expected);
Expand All @@ -128,7 +128,7 @@ public void testIss148()
{
final DefaultConfiguration checkConfig = createCheckConfig(NoNullForCollectionReturnCheck.class);
final String[] expected = {
"24: " + warningMessage,
"8: " + warningMessage,
};

verify(checkConfig, getPath("InputNoNullForCollectionReturnCheck7.java"), expected);
Expand All @@ -141,7 +141,7 @@ public void testIss148Deep()
final DefaultConfiguration checkConfig = createCheckConfig(NoNullForCollectionReturnCheck.class);
checkConfig.addAttribute("searchThroughMethodBody", "true");
final String[] expected = {
"24: " + warningMessage,
"8: " + warningMessage,
};

verify(checkConfig, getPath("InputNoNullForCollectionReturnCheck7.java"), expected);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.github.sevntu.checkstyle.checks.coding;
public class InputNoNullForCollectionReturnCheck1
{
private int[] method1()
{
return;
return new int[5];
}

private int[] method2()
Expand Down Expand Up @@ -58,7 +59,7 @@ private int[] method8()
return null; //!!
}
}
Boolean test;
Boolean test = false;
return test == null? new int[3] : new int[4];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.github.sevntu.checkstyle.checks.coding;
import java.util.*;
public class InputNoNullForCollectionReturnCheck2
{
private Collection method1()
{
return null; //!!
}

private Collection method2()
private LinkedList method2()
{
return new LinkedList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.github.sevntu.checkstyle.checks.coding;
public class InputNoNullForCollectionReturnCheck3
{
public Object[] scrollTo(BigDecimal revision) throws SQLException {
public Object[] scrollTo(String revision) throws Throwable {
Object[] record = null;

if (isReady()) {
if (r.compareTo(revision) == 0) {
record = new Object[resultSet.getMetaData().getColumnCount()];
if (true) {
if (true) {
record = new Object[10];
for (int index = 0; index < record.length; ++index) {
if (getColumnSqlTypes()[index] == Types.TIMESTAMP) {
record[index] = resultSet.getTimestamp(index + 1);
if (true) {
record[index] = "";
return null; //!!
} else {
record[index] = resultSet.getObject(index + 1);
record[index] = "";
return null; //!!
}
}
Expand All @@ -27,11 +28,11 @@ record = new Object[6];
public String[] method2()
{
String[] result = null;
if (!checkNotExists) {
result = new String[] { updateSql };
if (true) {
result = new String[] { };
} else {
result = new String[] { updateSql, removeItemsRelatedToDiscontinuedCompany(table, column) };
result = new String[] { };
}
return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.github.sevntu.checkstyle.checks.coding;
public interface InputNoNullForCollectionReturnCheck4
{
int[] method1();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.github.sevntu.checkstyle.checks.coding;
import java.util.LinkedList;
public class InputNoNullForCollectionReturnCheck5
{
private int[] method1()
{

Object hashFunction = null;
HashCode hash = ByteStreams.hash(new InputSupplier<InputStream>()
{
@Override
public InputStream getInput() throws IOException
public InputStream getInput() throws Exception
{
return null;
}
Expand All @@ -16,7 +17,7 @@ public LinkedList<Object> test()
return null; //!!
}
}, hashFunction);

Object metadataFileSum = null;
Files.write(hash.toString().getBytes(), metadataFileSum);

if(true)
Expand All @@ -31,12 +32,44 @@ private double[] method2()
boolean isCorrect = false;
if(isCorrect)
{
return 0.456;
return new double[4];
}
else
{
return null;
}
}

private class HashCode {

}

private static class ByteStreams {

public static
HashCode
hash(InputSupplier<InputStream> inputSupplier, Object hashFunction)
{
return null;
}

}

private class InputSupplier<T> {

}

private class InputStream {

}

private static class Files {

public static void write(byte[] bytes, Object metadataFileSum)
{

}

}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.github.sevntu.checkstyle.checks.coding;
public class InputNoNullForCollectionReturnCheck6
{
class DecoratableResourceMapping extends DecoratableResource {
class DecoratableResourceMapping {

public DecoratableResourceMapping(ResourceMapping mapping) {
if(projects == null || projects.length == 0)
public DecoratableResourceMapping() {
if("" != null || "".length() == 0)
return;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
package com.smth.cool;
package com.github.sevntu.checkstyle.checks.coding;

public class SecurityExchangeTool
public class InputNoNullForCollectionReturnCheck7
{

private Map loadData(final SqlStatement coListSql)
{
return (Map) new JdbcTemplate(ds).execute(new ConnectionCallback()
{
@Override
public Object doInConnection(Connection con)
throws SQLException,
DataAccessException
{
map.put(exch, new PartAndTotal(rs.getInt(2), (total != null ? total.intValue() : 0)));
return map;
}
});
}

private int[] method8()
{
Boolean test;
Boolean test = null;
return test == null? null : new int[4];
}
}

0 comments on commit 3a0dad2

Please sign in to comment.