Repository: redhat-developer/quarkus-ls
Pull request #1059: Do not generate property for `<clinit>`
Author: login: datho7561
Created: 2025-05-02T16:11:29Z | Merged: 2025-05-12T20:09:09Z

- [x] Needs a test

Fixes redhat-developer/vscode-quarkus#1019


Diff:
diff --git a/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/clinit/.gitignore b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/clinit/.gitignore
new file mode 100644
index 000000000..91a800a18
--- /dev/null
+++ b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/clinit/.gitignore
@@ -0,0 +1,45 @@
+#Maven
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+release.properties
+.flattened-pom.xml
+
+# Eclipse
+.project
+.classpath
+.settings/
+bin/
+
+# IntelliJ
+.idea
+*.ipr
+*.iml
+*.iws
+
+# NetBeans
+nb-configuration.xml
+
+# Visual Studio Code
+.vscode
+.factorypath
+
+# OSX
+.DS_Store
+
+# Vim
+*.swp
+*.swo
+
+# patch
+*.orig
+*.rej
+
+# Local environment
+.env
+
+# Plugin directory
+/.quarkus/cli/plugins/
+# TLS Certificates
+.certs/
diff --git a/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/clinit/pom.xml b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/clinit/pom.xml
new file mode 100644
index 000000000..c1138ad87
--- /dev/null
+++ b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/clinit/pom.xml
@@ -0,0 +1,124 @@
+<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>dev.datho7561</groupId>
+    <artifactId>clinit</artifactId>
+    <version>0.1.0-SNAPSHOT</version>
+
+    <properties>
+        <compiler-plugin.version>3.14.0</compiler-plugin.version>
+        <maven.compiler.release>21</maven.compiler.release>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
+        <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
+        <quarkus.platform.version>3.22.1</quarkus.platform.version>
+        <skipITs>true</skipITs>
+        <surefire-plugin.version>3.5.2</surefire-plugin.version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>${quarkus.platform.group-id}</groupId>
+                <artifactId>${quarkus.platform.artifact-id}</artifactId>
+                <version>${quarkus.platform.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-rest</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-arc</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.rest-assured</groupId>
+            <artifactId>rest-assured</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>${quarkus.platform.group-id}</groupId>
+                <artifactId>quarkus-maven-plugin</artifactId>
+                <version>${quarkus.platform.version}</version>
+                <extensions>true</extensions>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>build</goal>
+                            <goal>generate-code</goal>
+                            <goal>generate-code-tests</goal>
+                            <goal>native-image-agent</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>${compiler-plugin.version}</version>
+                <configuration>
+                    <parameters>true</parameters>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>${surefire-plugin.version}</version>
+                <configuration>
+                    <systemPropertyVariables>
+                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
+                        <maven.home>${maven.home}</maven.home>
+                    </systemPropertyVariables>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <version>${surefire-plugin.version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>integration-test</goal>
+                            <goal>verify</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <systemPropertyVariables>
+                        <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
+                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
+                        <maven.home>${maven.home}</maven.home>
+                    </systemPropertyVariables>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <profiles>
+        <profile>
+            <id>native</id>
+            <activation>
+                <property>
+                    <name>native</name>
+                </property>
+            </activation>
+            <properties>
+                <skipITs>false</skipITs>
+                <quarkus.native.enabled>true</quarkus.native.enabled>
+            </properties>
+        </profile>
+    </profiles>
+</project>
diff --git a/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/clinit/src/main/java/dev/datho7561/clinit/GreetingResource.java b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/clinit/src/main/java/dev/datho7561/clinit/GreetingResource.java
new file mode 100644
index 000000000..abe969754
--- /dev/null
+++ b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/clinit/src/main/java/dev/datho7561/clinit/GreetingResource.java
@@ -0,0 +1,16 @@
+package dev.datho7561.clinit;
+
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
+
+@Path("/hello")
+public class GreetingResource {
+
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String hello() {
+        return "Hello from Quarkus REST";
+    }
+}
diff --git a/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/clinit/src/main/resources/application.properties b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/projects/maven/clinit/src/main/resources/application.properties
new file mode 100644
index 000000000..e69de29bb
diff --git a/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/src/main/java/com/redhat/microprofile/jdt/quarkus/QuarkusConfigPropertiesTest.java b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/src/main/java/com/redhat/microprofile/jdt/quarkus/QuarkusConfigPropertiesTest.java
index 511cfa95e..c719f1617 100644
--- a/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/src/main/java/com/redhat/microprofile/jdt/quarkus/QuarkusConfigPropertiesTest.java
+++ b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/src/main/java/com/redhat/microprofile/jdt/quarkus/QuarkusConfigPropertiesTest.java
@@ -21,7 +21,6 @@
 import org.eclipse.lsp4mp.commons.MicroProfilePropertiesScope;
 import org.eclipse.lsp4mp.jdt.core.BasePropertiesManagerTest;
 import org.eclipse.lsp4mp.jdt.core.PropertiesManager;
-import org.eclipse.lsp4mp.jdt.core.project.JDTMicroProfileProject;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -293,5 +292,16 @@ public void configPropertiesVerbatimDefaultNamingStrategy() throws Exception {
 		assertPropertiesDuplicate(infoFromJavaSources);
 		Assert.assertEquals("Expected Quarkus properties count", EXPECTED_PROPERTIES, nbProperties);
 	}
+	
+	@Test
+	public void configPropertiesQuarkusArcRegression() throws Exception {
+		IJavaProject javaProject = loadMavenProject(QuarkusMavenProjectName.clinit);
+		MicroProfileProjectInfo infoFromJavaSourcesAndDeps = PropertiesManager.getInstance().getMicroProfileProjectInfo(
+				javaProject, MicroProfilePropertiesScope.SOURCES_AND_DEPENDENCIES, ClasspathKind.SRC,
+				JDT_UTILS, DocumentFormat.Markdown, new NullProgressMonitor());
+		for (var property : infoFromJavaSourcesAndDeps.getProperties()) {
+			Assert.assertFalse("Property should not end with <clinit>", property.getName().endsWith("<clinit>"));
+		}
+	}
 
 }
\ No newline at end of file
diff --git a/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/src/main/java/com/redhat/microprofile/jdt/quarkus/QuarkusMavenProjectName.java b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/src/main/java/com/redhat/microprofile/jdt/quarkus/QuarkusMavenProjectName.java
index f1f1e0eee..1e0a67099 100644
--- a/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/src/main/java/com/redhat/microprofile/jdt/quarkus/QuarkusMavenProjectName.java
+++ b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/src/main/java/com/redhat/microprofile/jdt/quarkus/QuarkusMavenProjectName.java
@@ -20,6 +20,6 @@ public class QuarkusMavenProjectName extends MicroProfileMavenProjectName {
 	public static String scheduler_quickstart = "scheduler-quickstart";
 	public static String scheduler_diagnostic = "scheduler-diagnostic";
 	public static final String quarkus_route = "quarkus-route";
-
+	public static final String clinit = "clinit";
 	public static final String quarkus_builditems = "quarkus-builditems";
-}
\ No newline at end of file
+}
diff --git a/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus/src/main/java/com/redhat/microprofile/jdt/internal/quarkus/core/properties/QuarkusConfigMappingProvider.java b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus/src/main/java/com/redhat/microprofile/jdt/internal/quarkus/core/properties/QuarkusConfigMappingProvider.java
index fe60c3802..fe35dd8c5 100644
--- a/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus/src/main/java/com/redhat/microprofile/jdt/internal/quarkus/core/properties/QuarkusConfigMappingProvider.java
+++ b/quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus/src/main/java/com/redhat/microprofile/jdt/internal/quarkus/core/properties/QuarkusConfigMappingProvider.java
@@ -137,7 +137,7 @@ private void populateConfigObject(IType configMappingType, String prefixStr, Str
 			if (child.getElementType() == IJavaElement.METHOD) {
 				IMethod method = (IMethod) child;
 				if (Flags.isDefaultMethod(method.getFlags()) || method.getNumberOfParameters() > 0
-						|| "void".equals(method.getReturnType())) {
+						|| "void".equals(method.getReturnType()) || "<clinit>".equals(method.getElementName())) {
 					continue;
 				}
 


Reviews:
user: login: angelozerr
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-12T18:46:16Z
user: login: datho7561
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-12T18:52:18Z
user: login: angelozerr
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-12T20:07:51Z

Review comments:
diff_hunk: @@ -20,6 +20,6 @@ public class QuarkusMavenProjectName extends MicroProfileMavenProjectName {
 	public static String scheduler_quickstart = "scheduler-quickstart";
 	public static String scheduler_diagnostic = "scheduler-diagnostic";
 	public static final String quarkus_route = "quarkus-route";
-
+	public static final String clinit = "clinit";
path: quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/src/main/java/com/redhat/microprofile/jdt/quarkus/QuarkusMavenProjectName.java
user: login: angelozerr
body: It seems that you don't use this constant, right?
created_at: 2025-05-12T18:46:16Z
author_association: CONTRIBUTOR
diff_hunk: @@ -20,6 +20,6 @@ public class QuarkusMavenProjectName extends MicroProfileMavenProjectName {
 	public static String scheduler_quickstart = "scheduler-quickstart";
 	public static String scheduler_diagnostic = "scheduler-diagnostic";
 	public static final String quarkus_route = "quarkus-route";
-
+	public static final String clinit = "clinit";
path: quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/src/main/java/com/redhat/microprofile/jdt/quarkus/QuarkusMavenProjectName.java
user: login: datho7561
body: I use it here https://github.com/redhat-developer/quarkus-ls/pull/1059/files#diff-5a589c56b38b81bf238303c13413a59cd85109cb5bd81389b2980f7d41852db8R298
created_at: 2025-05-12T18:52:18Z
author_association: CONTRIBUTOR
diff_hunk: @@ -20,6 +20,6 @@ public class QuarkusMavenProjectName extends MicroProfileMavenProjectName {
 	public static String scheduler_quickstart = "scheduler-quickstart";
 	public static String scheduler_diagnostic = "scheduler-diagnostic";
 	public static final String quarkus_route = "quarkus-route";
-
+	public static final String clinit = "clinit";
path: quarkus.jdt.ext/com.redhat.microprofile.jdt.quarkus.test/src/main/java/com/redhat/microprofile/jdt/quarkus/QuarkusMavenProjectName.java
user: login: angelozerr
body: Sorry I read too quickly your code.
created_at: 2025-05-12T20:07:51Z
author_association: CONTRIBUTOR

PR comments:
user: login: datho7561
created_at: 2025-05-02T16:21:25Z
body: @fbricon this fix should work, but several lsp4mp releases got deleted off nexus due to the storage failure. So it will only build if you have those artifacts locally or build them.

CI is going to be failing until we can restore those releases / make new SNAPSHOTs / a z release / something else? In order to do that though, we'll need the lsp4mp Jenkins CI back up.
author_association: CONTRIBUTOR
user: login: datho7561
created_at: 2025-05-12T18:07:52Z
body: @angelozerr if you have time, could you please take a look?

For your information, it's intended behaviour that `IType.getChildren()` returns `<clinit>` as one of the `IMethod` for binary types. `<clinit>` is the method that the compiler generates to set the value of the static members.
author_association: CONTRIBUTOR
user: login: angelozerr
created_at: 2025-05-12T20:08:46Z
body: LGTM, thanks @datho7561 !
author_association: CONTRIBUTOR