openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [JAVA] ClassCastException in org.openapitools.codegen.config.GlobalSettings#log

Open danijelz opened this issue 1 year ago • 0 comments

Description

When System Properties contain non String keys, the following exception is thrown:

java.lang.ClassCastException: class java.util.concurrent.locks.ReentrantLock cannot be cast to class java.lang.String (java.util.concurrent.locks.ReentrantLock and java.lang.String are in module java.base of loader 'bootstrap')
    at java.util.Properties.list (Properties.java:1257)
    at org.openapitools.codegen.config.GlobalSettings.log (GlobalSettings.java:73)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:946)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
openapi-generator version

The bug is present in 7.3.0 and still still not fixed in current master: GlobalSettings line 46 GlobalSettings line 73

Steps to reproduce

It happens while using maven plugin in combination with org.openhab.tools.sat:sat-plugin which seems to add non String key(s) to Properties. In any case, it's not right to rely on System Properties to only contain String keys if the Properties#list method is used which is explicitly documented to throw an error if non String keys are present: @throws ClassCastException if any key in this property list is not a string..

Suggest a fix

Either don't include System Properties when initializing Properties managed by GlobalSettings on line 46 or stop using Properties#list when logging Properties managed by GlobalSettings on line 73 .

danijelz avatar May 07 '24 13:05 danijelz