Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8199654

Type specification in diamond operators in generated ObjectFactory.java

XMLWordPrintable

    • x86_64
    • linux

      FULL PRODUCT VERSION :
      java -version
      java version "1.8.0_92"
      Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      3.0.101-107-default #1 SMP Thu Jun 22 14:37:55 UTC 2017 (414ea9f) x86_64 x86_64 x86_64 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      xjc -version
      xjc 2.3.0-b170531.0717


      A DESCRIPTION OF THE PROBLEM :
      When generating Java-classes with jaxb (xjc) the generated ObjectFactory contains type specification in diamond operators, which is not required anymore in Java SE 8 and above, and results in SonarQube violation: "Replace the type specification in this constructor call with the diamond operator ("<>")."

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Generate java-classes from a xsd with xjc

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
          @XmlElementDecl(namespace = "", name = "item")
          public JAXBElement<String> createItem(String value) {
              return new JAXBElement<>(_Item_QNAME, String.class, null, value);
          }
      ACTUAL -
          @XmlElementDecl(namespace = "", name = "item")
          public JAXBElement<String> createItem(String value) {
              return new JAXBElement<String>(_Item_QNAME, String.class, null, value);
          }

      "Replace the type specification in this constructor call with the diamond operator ("<>")." SonarQube violation

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      "Replace the type specification in this constructor call with the diamond operator ("<>")."

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      <?xml version="1.0" encoding="UTF-8" ?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      elementFormDefault="qualified">

      <xs:element name="item" type="xs:string">
      </xs:element>

      </xs:schema>
      ---------- END SOURCE ----------

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: