Skip to content

Commit ee8547f

Browse files
committed
Merge pull request #1900 from hiveship/fix-java-warnings
fix java warnings
2 parents ced433f + 4c7d471 commit ee8547f

File tree

117 files changed

+316
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+316
-290
lines changed

bin/go-petstore.sh

100755100644
File mode changed.

bin/windows/go-petstore.bat

100755100644
File mode changed.

modules/swagger-codegen-cli/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@
8989
<dependency>
9090
<groupId>org.testng</groupId>
9191
<artifactId>testng</artifactId>
92-
<version>${testng-version}</version>
92+
<!-- <version>${testng-version}</version> -->
9393
<scope>test</scope>
9494
</dependency>
9595
<dependency>
9696
<groupId>org.jmockit</groupId>
9797
<artifactId>jmockit</artifactId>
98-
<version>${jmockit-version}</version>
98+
<!-- <version>${jmockit-version}</version> -->
9999
<scope>test</scope>
100100
</dependency>
101101
</dependencies>

modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/SwaggerCodegen.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class SwaggerCodegen {
2121

2222

2323
public static void main(String[] args) {
24+
@SuppressWarnings("unchecked")
2425
Cli.CliBuilder<Runnable> builder = Cli.<Runnable>builder("swagger-codegen-cli")
2526
.withDescription("Swagger code generator CLI. More info on swagger.io")
2627
.withDefaultCommand(Langs.class)

modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,15 @@ private void setLanguageSpecificPrimitives(CodegenConfigurator configurator) {
230230
}
231231
}
232232

233-
private Set<String> createSetFromCsvList(String csvProperty) {
233+
private static Set<String> createSetFromCsvList(String csvProperty) {
234234
final List<String> values = OptionUtils.splitCommaSeparatedList(csvProperty);
235235
return new HashSet<String>(values);
236236
}
237237

238-
private Map createMapFromKeyValuePairs(String commaSeparatedKVPairs) {
238+
private static Map<String, String> createMapFromKeyValuePairs(String commaSeparatedKVPairs) {
239239
final List<Pair<String, String>> pairs = OptionUtils.parseCommaSeparatedTuples(commaSeparatedKVPairs);
240240

241-
Map result = new HashMap();
241+
Map<String, String> result = new HashMap<String, String>();
242242

243243
for (Pair<String, String> pair : pairs) {
244244
result.put(pair.getLeft(), pair.getRight());

modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Meta.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void run() {
9393
* @param data - map with additional params needed to process templates
9494
* @return converter object to pass to lambdaj
9595
*/
96-
private Converter<SupportingFile, File> processFiles(final File targetDir, final Map<String, Object> data) {
96+
private static Converter<SupportingFile, File> processFiles(final File targetDir, final Map<String, Object> data) {
9797
return new Converter<SupportingFile, File>() {
9898
private DefaultGenerator generator = new DefaultGenerator();
9999

@@ -133,7 +133,7 @@ public File convert(SupportingFile support) {
133133
* @param generator - class with reader getter
134134
* @return loader for template
135135
*/
136-
private Mustache.TemplateLoader loader(final DefaultGenerator generator) {
136+
private static Mustache.TemplateLoader loader(final DefaultGenerator generator) {
137137
return new Mustache.TemplateLoader() {
138138
@Override
139139
public Reader getTemplate(String name) {
@@ -149,7 +149,7 @@ public Reader getTemplate(String name) {
149149
* @param packageName - package name to convert
150150
* @return relative path
151151
*/
152-
private String asPath(String packageName) {
152+
private static String asPath(String packageName) {
153153
return packageName.replace(".", File.separator);
154154
}
155155
}

modules/swagger-codegen-cli/src/test/java/io/swagger/codegen/cmd/GenerateTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.commons.lang3.ArrayUtils;
1313
import org.testng.annotations.Test;
1414

15+
@SuppressWarnings("unused")
1516
public class GenerateTest {
1617

1718
@Mocked

modules/swagger-codegen-cli/src/test/java/io/swagger/codegen/cmd/utils/OptionUtilsTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import static org.testng.Assert.assertEquals;
1111
import static org.testng.Assert.assertNotNull;
1212

13+
@SuppressWarnings("static-method")
1314
public class OptionUtilsTest {
1415

1516
@Test
@@ -30,7 +31,7 @@ public void testParseCommaSeparatedTuples() throws Exception {
3031
doTupleListTest(null, new ArrayList<Pair<String, String>>());
3132
}
3233

33-
private void doTupleListTest(String input, List<Pair<String, String>> expectedResults) {
34+
private static void doTupleListTest(String input, List<Pair<String, String>> expectedResults) {
3435
final List<Pair<String, String>> result = OptionUtils.parseCommaSeparatedTuples(input);
3536
assertNotNull(result);
3637
assertEquals(result.size(), expectedResults.size());
@@ -41,7 +42,7 @@ private void doTupleListTest(String input, List<Pair<String, String>> expectedRe
4142
}
4243
}
4344

44-
private void doCommaSeparatedListTest(String csvStr, List<String> expectedResults) {
45+
private static void doCommaSeparatedListTest(String csvStr, List<String> expectedResults) {
4546
final List<String> result = OptionUtils.splitCommaSeparatedList(csvStr);
4647
assertNotNull(result);
4748
assertEquals(result.size(), expectedResults.size());

modules/swagger-codegen-maven-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<dependency>
5252
<groupId>junit</groupId>
5353
<artifactId>junit</artifactId>
54-
<version>4.12</version>
54+
<!-- <version>4.12</version> -->
5555
<scope>test</scope>
5656
</dependency>
5757
</dependencies>

modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class CodeGenMojo extends AbstractMojo {
9999
* A map of language-specific parameters as passed with the -c option to the command line
100100
*/
101101
@Parameter(name = "configOptions")
102-
private Map configOptions;
102+
private Map<?, ?> configOptions;
103103

104104
/**
105105
* Add the output directory to the project as a source root, so that the

modules/swagger-codegen/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<plugin>
102102
<groupId>org.apache.maven.plugins</groupId>
103103
<artifactId>maven-release-plugin</artifactId>
104-
<version>2.1</version>
104+
<!-- <version>2.1</version> -->
105105
</plugin>
106106
<plugin>
107107
<groupId>org.apache.maven.plugins</groupId>
@@ -256,7 +256,7 @@
256256
<dependency>
257257
<groupId>org.testng</groupId>
258258
<artifactId>testng</artifactId>
259-
<version>${testng-version}</version>
259+
<!-- <version>${testng-version}</version> -->
260260
<scope>test</scope>
261261
</dependency>
262262
<dependency>
@@ -268,7 +268,7 @@
268268
<dependency>
269269
<groupId>org.jmockit</groupId>
270270
<artifactId>jmockit</artifactId>
271-
<version>${jmockit-version}</version>
271+
<!-- <version>${jmockit-version}</version> -->
272272
<scope>test</scope>
273273
</dependency>
274274
</dependencies>

modules/swagger-codegen/src/main/java/io/swagger/codegen/AbstractGenerator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
public abstract class AbstractGenerator {
1616

17+
@SuppressWarnings("static-method")
1718
public File writeToFile(String filename, String contents) throws IOException {
1819
System.out.println("writing file " + filename);
1920
File output = new File(filename);
@@ -48,10 +49,7 @@ public Reader getTemplateReader(String name) {
4849
try {
4950
InputStream is = this.getClass().getClassLoader().getResourceAsStream(getCPResourcePath(name));
5051
if (is == null) {
51-
is = new FileInputStream(new File(name));
52-
}
53-
if (is == null) {
54-
throw new RuntimeException("no file found");
52+
is = new FileInputStream(new File(name)); // May throw but never return a null value
5553
}
5654
return new InputStreamReader(is);
5755
} catch (Exception e) {
@@ -96,6 +94,7 @@ public boolean embeddedTemplateExists(String name) {
9694
return this.getClass().getClassLoader().getResource(getCPResourcePath(name)) != null;
9795
}
9896

97+
@SuppressWarnings("static-method")
9998
public String getCPResourcePath(String name) {
10099
if (!"/".equals(File.separator)) {
101100
return name.replaceAll(Pattern.quote(File.separator), "/");

modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOptInput.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@
55
import io.swagger.models.Swagger;
66
import io.swagger.models.auth.AuthorizationValue;
77

8-
import java.net.URLDecoder;
9-
import java.net.URLEncoder;
10-
import java.util.ArrayList;
118
import java.util.List;
129

13-
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
14-
1510
public class ClientOptInput {
1611
private CodegenConfig config;
1712
private ClientOpts opts;

modules/swagger-codegen/src/main/java/io/swagger/codegen/Codegen.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.apache.commons.cli.Options;
1212

1313
import java.util.ArrayList;
14-
import java.util.Arrays;
1514
import java.util.HashMap;
1615
import java.util.Iterator;
1716
import java.util.List;
@@ -32,10 +31,9 @@ public class Codegen extends DefaultGenerator {
3231
"\n -DdebugOperations prints operations passed to the template engine" +
3332
"\n -DdebugSupportingFiles prints additional data passed to the template engine";
3433

34+
@SuppressWarnings("deprecation")
3535
public static void main(String[] args) {
3636

37-
StringBuilder sb = new StringBuilder();
38-
3937
Options options = new Options();
4038
options.addOption("h", "help", false, "shows this message");
4139
options.addOption("l", "lang", true, "client language to generate.\nAvailable languages include:\n\t[" + configString + "]");
@@ -139,7 +137,7 @@ public static CodegenConfig getConfig(String name) {
139137
// see if it's a class
140138
try {
141139
System.out.println("loading class " + name);
142-
Class customClass = Class.forName(name);
140+
Class<?> customClass = Class.forName(name);
143141
System.out.println("loaded");
144142
return (CodegenConfig) customClass.newInstance();
145143
} catch (Exception e) {

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class CodegenOperation {
3838
*
3939
* @return true if parameter exists, false otherwise
4040
*/
41-
private boolean nonempty(List<CodegenParameter> params) {
41+
private static boolean nonempty(List<CodegenParameter> params) {
4242
return params != null && params.size() > 0;
4343
}
4444

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,50 @@ public class CodegenProperty {
4040
public CodegenProperty items;
4141
public Map<String, Object> vendorExtensions;
4242

43+
@Override
44+
public int hashCode()
45+
{
46+
final int prime = 31;
47+
int result = 1;
48+
result = prime * result + ((_enum == null) ? 0 : _enum.hashCode());
49+
result = prime * result + ((allowableValues == null) ? 0 : allowableValues.hashCode());
50+
result = prime * result + ((baseName == null) ? 0 : baseName.hashCode());
51+
result = prime * result + ((baseType == null) ? 0 : baseType.hashCode());
52+
result = prime * result + ((complexType == null) ? 0 : complexType.hashCode());
53+
result = prime * result + ((containerType == null) ? 0 : containerType.hashCode());
54+
result = prime * result + ((datatype == null) ? 0 : datatype.hashCode());
55+
result = prime * result + ((datatypeWithEnum == null) ? 0 : datatypeWithEnum.hashCode());
56+
result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
57+
result = prime * result + ((defaultValueWithParam == null) ? 0 : defaultValueWithParam.hashCode());
58+
result = prime * result + ((description == null) ? 0 : description.hashCode());
59+
result = prime * result + ((example == null) ? 0 : example.hashCode());
60+
result = prime * result + ((exclusiveMaximum == null) ? 0 : exclusiveMaximum.hashCode());
61+
result = prime * result + ((exclusiveMinimum == null) ? 0 : exclusiveMinimum.hashCode());
62+
result = prime * result + ((getter == null) ? 0 : getter.hashCode());
63+
result = prime * result + ((hasMore == null) ? 0 : hasMore.hashCode());
64+
result = prime * result + ((isContainer == null) ? 0 : isContainer.hashCode());
65+
result = prime * result + (isEnum ? 1231 : 1237);
66+
result = prime * result + ((isNotContainer == null) ? 0 : isNotContainer.hashCode());
67+
result = prime * result + ((isPrimitiveType == null) ? 0 : isPrimitiveType.hashCode());
68+
result = prime * result + ((isReadOnly == null) ? 0 : isReadOnly.hashCode());
69+
result = prime * result + ((items == null) ? 0 : items.hashCode());
70+
result = prime * result + ((jsonSchema == null) ? 0 : jsonSchema.hashCode());
71+
result = prime * result + ((max == null) ? 0 : max.hashCode());
72+
result = prime * result + ((maxLength == null) ? 0 : maxLength.hashCode());
73+
result = prime * result + ((maximum == null) ? 0 : maximum.hashCode());
74+
result = prime * result + ((min == null) ? 0 : min.hashCode());
75+
result = prime * result + ((minLength == null) ? 0 : minLength.hashCode());
76+
result = prime * result + ((minimum == null) ? 0 : minimum.hashCode());
77+
result = prime * result + ((name == null) ? 0 : name.hashCode());
78+
result = prime * result + ((pattern == null) ? 0 : pattern.hashCode());
79+
result = prime * result + ((required == null) ? 0 : required.hashCode());
80+
result = prime * result + ((secondaryParam == null) ? 0 : secondaryParam.hashCode());
81+
result = prime * result + ((setter == null) ? 0 : setter.hashCode());
82+
result = prime * result + ((unescapedDescription == null) ? 0 : unescapedDescription.hashCode());
83+
result = prime * result + ((vendorExtensions == null) ? 0 : vendorExtensions.hashCode());
84+
return result;
85+
}
86+
4387
@Override
4488
public boolean equals(Object obj) {
4589
if (obj == null) {

0 commit comments

Comments
 (0)