Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java generation from CustomResourceDefinition yaml: descriptions containing "*/" lead to compile error #4818

Closed
miriSch opened this issue Feb 1, 2023 · 2 comments · Fixed by #4819
Assignees
Milestone

Comments

@miriSch
Copy link
Contributor

miriSch commented Feb 1, 2023

Describe the bug

If custom resource definitions contain the character sequence which ends a javadoc comment, the generated java files are not compiling.
java-generator-maven-plugin with version 6.4.1 was used, same problem also for version 6.3.1

Fabric8 Kubernetes Client version

6.4.1

Steps to reproduce

  1. create a maven project with the following files:
    • pom.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <project xmlns="http://maven.apache.org/POM/4.0.0"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
      
          <groupId>org.example</groupId>
          <artifactId>javadoc-escape</artifactId>
          <version>1.0-SNAPSHOT</version>
      
          <properties>
              <maven.compiler.source>11</maven.compiler.source>
              <maven.compiler.target>11</maven.compiler.target>
              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          </properties>
      
          <dependencies>
              <dependency>
                  <groupId>io.fabric8</groupId>
                  <artifactId>kubernetes-client</artifactId>
                  <version>6.4.1</version>
              </dependency>
              <dependency>
                  <groupId>io.fabric8</groupId>
                  <artifactId>generator-annotations</artifactId>
                  <version>6.4.1</version>
              </dependency>
          </dependencies>
      
          <build>
              <plugins>
                  <plugin>
                      <groupId>io.fabric8</groupId>
                      <artifactId>java-generator-maven-plugin</artifactId>
                      <version>6.4.1</version>
                      <executions>
                          <execution>
                              <goals>
                                  <goal>generate</goal>
                              </goals>
                              <id>crd-generator</id>
                          </execution>
                      </executions>
                      <configuration>
                          <source>${project.basedir}/src/main/resources</source>
                      </configuration>
                  </plugin>
              </plugins>
          </build>
      
      </project>
      
    • src/main/java/org/example/Main.java
      package org.example;
      
      public class Main {
          public static void main(String[] args) {
              System.out.println("Hello world!");
          }
      }
      
    • src/main/resources/example-crd.yaml
      apiVersion: apiextensions.k8s.io/v1
      kind: CustomResourceDefinition
      metadata:
       name: dummies.example.com
      spec:
       group: example.com
       versions:
         - name: v1
           served: true
           storage: true
           schema:
             openAPIV3Schema:
               type: object
               properties:
                 spec:
                   type: object
                   properties:
                     someField:
                       type: string
                       description: some text containing */ javadoc end
       scope: Namespaced
       names:
         plural: dummies
         singular: dummy
         kind: Dummy
      
  2. run mvn clean compile

Current behavior:

  • build fails with the following output (paths anonymized):
    [INFO] Scanning for projects...
    [INFO] 
    [INFO] ---------------------< org.example:javadoc-escape >---------------------
    [INFO] Building javadoc-escape 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ javadoc-escape ---
    [INFO] Deleting /exampleprojectpath/javadoc-escape/target
    [INFO] 
    [INFO] --- java-generator-maven-plugin:6.4.1:generate (crd-generator) @ javadoc-escape ---
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ javadoc-escape ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ javadoc-escape ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 3 source files to /exampleprojectpath/javadoc-escape/target/classes
    [INFO] -------------------------------------------------------------
    [ERROR] COMPILATION ERROR : 
    [INFO] -------------------------------------------------------------
    [ERROR] /exampleprojectpath/javadoc-escape/target/generated-sources/java/com/example/v1/DummySpec.java:[10,43] ';' expected
    [INFO] 1 error
    [INFO] -------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  0.962 s
    [INFO] Finished at: 2023-02-01T09:03:39+01:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project javadoc-escape: Compilation failure
    [ERROR] /exampleprojectpath/javadoc-escape/target/generated-sources/java/com/example/v1/DummySpec.java:[10,43] ';' expected
    [ERROR] 
    [ERROR] -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
    
  • generated DummySpec.java looks as follows:
    package com.example.v1;
    
    @com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
    @com.fasterxml.jackson.annotation.JsonPropertyOrder({"someField"})
    @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.fasterxml.jackson.databind.JsonDeserializer.None.class)
    @javax.annotation.processing.Generated("io.fabric8.java.generator.CRGeneratorRunner")
    public class DummySpec implements io.fabric8.kubernetes.api.model.KubernetesResource {
    
        /**
         * some text containing */ javadoc end
         */
        @com.fasterxml.jackson.annotation.JsonProperty("someField")
        @com.fasterxml.jackson.annotation.JsonPropertyDescription("some text containing */ javadoc end")
        @com.fasterxml.jackson.annotation.JsonSetter(nulls = com.fasterxml.jackson.annotation.Nulls.SKIP)
        private String someField;
    
        public String getSomeField() {
            return someField;
        }
    
        public void setSomeField(String someField) {
            this.someField = someField;
        }
    }
    

Expected behavior

A successful maven build is expected which generated classes Dummy and DummySpec and compiled them.

This could be achived for example by replacing the / in descriptions with &#47 during code generation.
The expected generated DummySpec.java would then look like:

package com.example.v1;

@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
@com.fasterxml.jackson.annotation.JsonPropertyOrder({"someField"})
@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.fasterxml.jackson.databind.JsonDeserializer.None.class)
@javax.annotation.processing.Generated("io.fabric8.java.generator.CRGeneratorRunner")
public class DummySpec implements io.fabric8.kubernetes.api.model.KubernetesResource {

    /**
     * some text containing *&#47 javadoc end
     */
    @com.fasterxml.jackson.annotation.JsonProperty("someField")
    @com.fasterxml.jackson.annotation.JsonPropertyDescription("some text containing */ javadoc end")
    @com.fasterxml.jackson.annotation.JsonSetter(nulls = com.fasterxml.jackson.annotation.Nulls.SKIP)
    private String someField;

    public String getSomeField() {
        return someField;
    }

    public void setSomeField(String someField) {
        this.someField = someField;
    }
}

Runtime

other (please specify in additional context)

Kubernetes API Server version

other (please specify in additional context)

Environment

Linux

Fabric8 Kubernetes Client Logs

No response

Additional context

no kubernetes runtime or API server needed for reproducing this bug

@andreaTP
Copy link
Member

andreaTP commented Feb 1, 2023

Thanks for reporting @miriSch !

@miriSch
Copy link
Contributor Author

miriSch commented Feb 6, 2023

Thanks for fixing @andreaTP! Looking forward to the release containing the fix :)

@manusa manusa added this to the 6.5.0 milestone Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants