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

JSON Schema with enumerated string property issue #90

Closed
marksto opened this issue May 17, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@marksto
Copy link

commented May 17, 2019

Describe the bug
Actually, there are two separate issues, but I see them as a common place for improvement.

  1. JSON Schema type with required enumerated string property doesn't seem to work properly with create(...) (passes only with a null argument)
  2. It is impossible to add a single-char enum value (e.g. "?") because of an improper generated Java name (it will be a single _ char which is prohibited in JDK 9+)

To Reproduce
Checkout the test project.
Run mvn clean install.

Expected behavior
No error/exception in both cases.
In the second case I'd expect __ instead of _ (this is totally fine for an invalid character until other suitable Unicode characters manage to get into the name, e.g. "да" is translated into да("да") — and it seems to do so at the moment).

Screenshots
A screenshot of the compilation error hint in the second case.
Снимок экрана 2019-05-17 в 2 29 33

Desktop (please complete the following information):

  • OS Type & Version: "mac os x", version: "10.14.4", arch: "x86_64", family: "mac"
  • Java/JDK version: Java 9+ / openjdk version "12.0.1" 2019-04-16
  • IntelliJ IDEA version: 2019.1
  • Manifold version: 0.68-alpha
  • Manifold IntelliJ plugin version: 0.68-alpha

Stack trace

  1. In case you try to instantiate a type with required enum string property — runtime exception:
java.lang.IllegalStateException: Unsupported expando type: class abc.res.EnumTest$ind
	at manifold.util.JsonUtil.appendValue(JsonUtil.java:241)
	at manifold.util.JsonUtil.toJson(JsonUtil.java:96)
	at manifold.util.JsonUtil.toJson(JsonUtil.java:138)
	at manifold.util.JsonUtil.toJson(JsonUtil.java:118)
	at manifold.api.json.Writer.toJson(Writer.java:51)
	at abc.RunMe.test_Enum_Init(RunMe.java:27)
	at abc.RunMe.main(RunMe.java:11)
	at abc.TestMe.testMe(TestMe.java:7)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at junit.framework.TestCase.runTest(TestCase.java:176)
	at junit.framework.TestCase.runBare(TestCase.java:141)
	at junit.framework.TestResult$1.protect(TestResult.java:122)
	at junit.framework.TestResult.runProtected(TestResult.java:142)
	at junit.framework.TestResult.run(TestResult.java:125)
	at junit.framework.TestCase.run(TestCase.java:129)
	at junit.framework.TestSuite.runTest(TestSuite.java:252)
	at junit.framework.TestSuite.run(TestSuite.java:247)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

  1. In case you add an extra single-char enum value (e.g. "?") — compilation error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project manifold-json-schema-test: Compilation failure
[ERROR] as of release 9, '_' is a keyword, and may not be used as an identifier
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project manifold-json-schema-test: Compilation failure
as of release 9, '_' is a keyword, and may not be used as an identifier

	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
	at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
as of release 9, '_' is a keyword, and may not be used as an identifier

	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1215)
	at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:188)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	... 21 more

@rsmckinney rsmckinney added the bug label May 17, 2019

@rsmckinney

This comment has been minimized.

Copy link
Member

commented May 17, 2019

Good catch! A fix will be available soon. Thanks for reporting this!

rsmckinney added a commit that referenced this issue May 18, 2019

Manifold core change
-#90
-- improve encoding of an identifier with all invalid characters
-- coerce json api create/build parameters to binding values
-- fix npe
@rsmckinney

This comment has been minimized.

Copy link
Member

commented May 19, 2019

Fix available in release 0.69-alpha

@rsmckinney rsmckinney closed this May 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.