Andrea Campanella
Committed by Gerrit Code Review

ONOS-3530 Fix array out of bounds in case of no @param value description

Change-Id: I336a7645547f844e11ab08cc3cf9f403fa42d890
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
54 54
55 <module>tools/package/archetypes</module> 55 <module>tools/package/archetypes</module>
56 <module>tools/package/branding</module> 56 <module>tools/package/branding</module>
57 + <module>tools/package/maven-plugin</module>
57 </modules> 58 </modules>
58 59
59 <url>http://onosproject.org/</url> 60 <url>http://onosproject.org/</url>
...@@ -79,6 +80,7 @@ ...@@ -79,6 +80,7 @@
79 <copycat.version>0.5.0.onos</copycat.version> 80 <copycat.version>0.5.0.onos</copycat.version>
80 <!-- FIXME update to release version before Emu release --> 81 <!-- FIXME update to release version before Emu release -->
81 <openflowj.version>0.9.2.onos-SNAPSHOT</openflowj.version> 82 <openflowj.version>0.9.2.onos-SNAPSHOT</openflowj.version>
83 + <onos-maven-plugin.version>1.7-SNAPSHOT</onos-maven-plugin.version>
82 <karaf.version>3.0.3</karaf.version> 84 <karaf.version>3.0.3</karaf.version>
83 <jersey.version>1.19</jersey.version> 85 <jersey.version>1.19</jersey.version>
84 </properties> 86 </properties>
...@@ -654,7 +656,7 @@ ...@@ -654,7 +656,7 @@
654 <plugin> 656 <plugin>
655 <groupId>org.onosproject</groupId> 657 <groupId>org.onosproject</groupId>
656 <artifactId>onos-maven-plugin</artifactId> 658 <artifactId>onos-maven-plugin</artifactId>
657 - <version>1.6</version> 659 + <version>${onos-maven-plugin.version}</version>
658 <executions> 660 <executions>
659 <execution> 661 <execution>
660 <id>cfg</id> 662 <id>cfg</id>
......
...@@ -293,7 +293,7 @@ public class OnosSwaggerMojo extends AbstractMojo { ...@@ -293,7 +293,7 @@ public class OnosSwaggerMojo extends AbstractMojo {
293 + param + ".json"); 293 + param + ".json");
294 String lines = Files.readLines(config, Charsets.UTF_8).stream().reduce((t, u) -> t + u). 294 String lines = Files.readLines(config, Charsets.UTF_8).stream().reduce((t, u) -> t + u).
295 get(); 295 get();
296 - lines = lines.replaceAll("\\s+",""); 296 + lines = lines.replaceAll("\\s+", "");
297 definitions.putPOJO(param, lines); 297 definitions.putPOJO(param, lines);
298 } catch (IOException e) { 298 } catch (IOException e) {
299 e.printStackTrace(); 299 e.printStackTrace();
...@@ -352,7 +352,7 @@ public class OnosSwaggerMojo extends AbstractMojo { ...@@ -352,7 +352,7 @@ public class OnosSwaggerMojo extends AbstractMojo {
352 private String getIOType(JavaAnnotation annotation) { 352 private String getIOType(JavaAnnotation annotation) {
353 if (annotation.getNamedParameter("value").toString().equals(JSON)) { 353 if (annotation.getNamedParameter("value").toString().equals(JSON)) {
354 return "application/json"; 354 return "application/json";
355 - } else if (annotation.getNamedParameter("value").toString().equals(OCTET_STREAM)){ 355 + } else if (annotation.getNamedParameter("value").toString().equals(OCTET_STREAM)) {
356 return "application/octet_stream"; 356 return "application/octet_stream";
357 } 357 }
358 return ""; 358 return "";
...@@ -408,15 +408,21 @@ public class OnosSwaggerMojo extends AbstractMojo { ...@@ -408,15 +408,21 @@ public class OnosSwaggerMojo extends AbstractMojo {
408 } 408 }
409 for (DocletTag p : javaMethod.getTagsByName("param")) { 409 for (DocletTag p : javaMethod.getTagsByName("param")) {
410 if (p.getValue().contains(annotationName)) { 410 if (p.getValue().contains(annotationName)) {
411 - try { 411 + String description = "";
412 - String description = p.getValue().split(" ", 2)[1].trim(); 412 + if (p.getValue().split(" ", 2).length >= 2) {
413 + description = p.getValue().split(" ", 2)[1].trim();
413 if (description.contains("optional")) { 414 if (description.contains("optional")) {
414 required = false; 415 required = false;
415 } 416 }
416 - individualParameterNode.put("description", description); 417 + } else {
417 - } catch (Exception e) { 418 + getLog().warn(String.format(
418 - e.printStackTrace(); 419 + "No description for parameter \"%s\" in " +
420 + "method \"%s\" in %s (line %d)",
421 + p.getValue(), javaMethod.getName(),
422 + javaMethod.getDeclaringClass().getName(),
423 + javaMethod.getLineNumber()));
419 } 424 }
425 + individualParameterNode.put("description", description);
420 } 426 }
421 } 427 }
422 individualParameterNode.put("required", required); 428 individualParameterNode.put("required", required);
......