stoicflame / enunciate

Build-time enhancement tool for Java-based Web services projects
http://enunciate.webcohesion.com/
Other
480 stars 200 forks source link

enunciate-maven-plugin failed to compile Java JSON client-side classes with generic type #1177

Closed ChambreNoire closed 1 month ago

ChambreNoire commented 1 year ago

Hi,

I'm updating a legacy project using java 8 and enunciate-maven-plugin version 2.13.0. I have updated to jdk 11 and enunciate-maven-plugin 2.15.1 and since this I have encountered problems.

parent-pom

<profile>
    <id>jax-rs-api</id>
    <dependencies>
        <dependency>
            <groupId>com.webcohesion.enunciate</groupId>
            <artifactId>enunciate-core-annotations</artifactId>
            <version>${enunciate-maven-plugin.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>com.webcohesion.enunciate</groupId>
                <artifactId>enunciate-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>docs</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

When the plugin is run by maven upon deploy, the following dto is not correctly compiled.

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  26.953 s
[INFO] Finished at: 2023-07-19T10:44:33+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.webcohesion.enunciate:enunciate-maven-plugin:2.15.0:docs (default) on project my-project: Compile failed of Java JSON client-side classes. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.webcohesion.enunciate:enunciate-maven-plugin:2.15.0:docs (default) on project my-project: Compile failed of Java JSON client-side classes.
public abstract class IdentityView<T> {

    private String accountId;
    private T profile;
    private ConfigurationView configuration;

    // setters & getters
}
C:\...\my-project\target\enunciate\java-json-client\src\com\my-project\data\view\IdentityView.java:21: error: illegal start of type
  private ? _profile;
          ^
C:\...\my-project\target\enunciate\java-json-client\src\com\my-project\data\view\IdentityView.java:21: error: <identifier> expected
  private ? _profile;
                    ^
C:\...\my-project\target\enunciate\java-json-client\src\com\my-project\data\view\IdentityView.java:45: error: illegal start of type
  public ? getProfile() {
         ^
C:\...\my-project\target\enunciate\java-json-client\src\com\my-project\data\view\IdentityView.java:45: error: invalid method declaration; return type required
  public ? getProfile() {
           ^
C:\...\my-project\target\enunciate\java-json-client\src\com\my-project\data\view\IdentityView.java:53: error: illegal start of type
  public void setProfile(? _profile) {

Any ideas ?

Many thanks in advance!

stoicflame commented 1 year ago

Looks like a bug in the java-json-client module. I'll look into it.

Can you share what your getters and setters look like for the profile property of the IdentityView class? Is it just something like:

public T getProfile() {
  ...
}

public void setProfile(T profile) {
  ...
}
ChambreNoire commented 12 months ago

@stoicflame yup that's exactly it, just basic getters & setters:

public T getProfile() {
    return this.profile;
}

public void setProfile(T profile) {
    this.profile = profile;
}

Thanks

stoicflame commented 9 months ago

I'm attempted to reproduce this, but everything seems to work for me.

Here's a diff I applied to enunciate-sample, can you tell me how to modify it to expose the problem?

diff --git a/enunciate-sample-model/src/main/java/com/webcohesion/enunciate/sample/model/Identity.java b/enunciate-sample-model/src/main/java/com/webcohesion/enunciate/sample/model/Identity.java
new file mode 100644
index 0000000..e614977
--- /dev/null
+++ b/enunciate-sample-model/src/main/java/com/webcohesion/enunciate/sample/model/Identity.java
@@ -0,0 +1,17 @@
+/*
+ * © 2023 by Intellectual Reserve, Inc. All rights reserved.
+ */
+package com.webcohesion.enunciate.sample.model;
+
+public abstract class Identity<T> {
+  
+  private T name;
+
+  public T getName() {
+    return name;
+  }
+
+  public void setName(T name) {
+    this.name = name;
+  }
+}
diff --git a/enunciate-sample-model/src/main/java/com/webcohesion/enunciate/sample/model/NamedIdentity.java b/enunciate-sample-model/src/main/java/com/webcohesion/enunciate/sample/model/NamedIdentity.java
new file mode 100644
index 0000000..1383f8d
--- /dev/null
+++ b/enunciate-sample-model/src/main/java/com/webcohesion/enunciate/sample/model/NamedIdentity.java
@@ -0,0 +1,7 @@
+/*
+ * © 2023 by Intellectual Reserve, Inc. All rights reserved.
+ */
+package com.webcohesion.enunciate.sample.model;
+
+public class NamedIdentity extends Identity<Name> {
+}
diff --git a/enunciate-sample-model/src/main/java/com/webcohesion/enunciate/sample/model/Person.java b/enunciate-sample-model/src/main/java/com/webcohesion/enunciate/sample/model/Person.java
index e04bd02..e8187ff 100644
--- a/enunciate-sample-model/src/main/java/com/webcohesion/enunciate/sample/model/Person.java
+++ b/enunciate-sample-model/src/main/java/com/webcohesion/enunciate/sample/model/Person.java
@@ -30,6 +30,7 @@ public class Person {
   private String alias;
   private Name name;
   private jakarta.activation.DataHandler picture;
+  private NamedIdentity identity;

   public String getId() {
     return id;
@@ -70,4 +71,12 @@ public class Person {
   public void setPicture(DataHandler picture) {
     this.picture = picture;
   }
+
+  public NamedIdentity getIdentity() {
+    return identity;
+  }
+
+  public void setIdentity(NamedIdentity identity) {
+    this.identity = identity;
+  }
 }
stoicflame commented 1 month ago

No updates, closing this out. I'm happy to re-open as needed.