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-generator] field names containing slashes lead to compile error #5164

Closed
miriSch opened this issue May 23, 2023 · 1 comment · Fixed by #5165
Closed

[java-generator] field names containing slashes lead to compile error #5164

miriSch opened this issue May 23, 2023 · 1 comment · Fixed by #5165
Labels
Milestone

Comments

@miriSch
Copy link
Contributor

miriSch commented May 23, 2023

Describe the bug

If a CRD file contains a field with a name that contains slash, the generated classes are not compiling.

Fabric8 Kubernetes Client version

6.6.2

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>property-slash</artifactId>
           <version>1.0-SNAPSHOT</version>
      
           <properties>
               <maven.compiler.source>17</maven.compiler.source>
               <maven.compiler.target>17</maven.compiler.target>
               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
           </properties>
      
           <dependencies>
               <dependency>
                   <groupId>io.fabric8</groupId>
                   <artifactId>kubernetes-client</artifactId>
                   <version>6.6.2</version>
               </dependency>
               <dependency>
                   <groupId>io.fabric8</groupId>
                   <artifactId>generator-annotations</artifactId>
                   <version>6.6.2</version>
               </dependency>
           </dependencies>
      
           <build>
               <plugins>
      
                   <plugin>
                       <groupId>io.fabric8</groupId>
                       <artifactId>java-generator-maven-plugin</artifactId>
                       <version>6.6.2</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-slash.yaml
      apiVersion: apiextensions.k8s.io/v1
      kind: CustomResourceDefinition
      metadata:
        name: slashdummies.example.com
      spec:
        group: example.com
        versions:
          - name: v1
            served: true
            storage: true
            schema:
              openAPIV3Schema:
                type: object
                properties:
                  spec:
                    type: object
                    properties:
                      with/slash:
                        type: string
        scope: Namespaced
        names:
          plural: slashdummies
          singular: slashdummy
          kind: SlashDummy
      
  2. run mvn clean compile

Current behavior

  • build fails with the following output (paths anonymized):
    [INFO] Scanning for projects...
    [INFO] 
    [INFO] ---------------------< org.example:property-slash >---------------------
    [INFO] Building property-slash 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ property-slash ---
    [INFO] Deleting /exampleprojectpath/property-slash/target
    [INFO] 
    [INFO] --- java-generator-maven-plugin:6.6.2:generate (crd-generator) @ property-slash ---
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ property-slash ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ property-slash ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 3 source files to /exampleprojectpath/property-slash/target/classes
    [INFO] -------------------------------------------------------------
    [ERROR] COMPILATION ERROR : 
    [INFO] -------------------------------------------------------------
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[11,24] ';' expected
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[11,30] <identifier> expected
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[13,26] ';' expected
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[13,27] invalid method declaration; return type required
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[17,24] '(' expected
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[17,25] invalid method declaration; return type required
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[17,42] ',', ')', or '[' expected
    [INFO] 7 errors 
    [INFO] -------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  1.030 s
    [INFO] Finished at: 2023-05-23T07:52:00+02:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project property-slash: Compilation failure: Compilation failure: 
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[11,24] ';' expected
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[11,30] <identifier> expected
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[13,26] ';' expected
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[13,27] invalid method declaration; return type required
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[17,24] '(' expected
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[17,25] invalid method declaration; return type required
    [ERROR] /exampleprojectpath/property-slash/target/generated-sources/java/com/example/v1/SlashDummySpec.java:[17,42] ',', ')', or '[' expected
    [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:
    
  • generated SlashDummySpec.java looks like:
    package com.example.v1;
    
    @com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
    @com.fasterxml.jackson.annotation.JsonPropertyOrder({"with/slash"})
    @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 SlashDummySpec implements io.fabric8.kubernetes.api.model.KubernetesResource {
    
        @com.fasterxml.jackson.annotation.JsonProperty("with/slash")
        @com.fasterxml.jackson.annotation.JsonSetter(nulls = com.fasterxml.jackson.annotation.Nulls.SKIP)
        private String with/slash;
    
        public String getWith/slash() {
            return with/slash;
        }
    
        public void setWith/slash(String with/slash) {
            this.with/slash = with/slash;
        }
    }
    

Expected behavior

A successful maven build is expected which generated classes SlashDummy and SlashDummySpec and compiled them.

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 to reproduce this bug

@miriSch
Copy link
Contributor Author

miriSch commented May 23, 2023

This bug is similar to the following one: #4823. I implemented a fix which I already suggested there (#4823 (comment)) to hopefully prevent further bugs of this type.

@manusa manusa added the bug label May 23, 2023
@manusa manusa added this to the 6.7.0 milestone May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants