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

[BUG] InaccessibleObjectException: Unable to make field transient #13684

Open
4 of 6 tasks
Santobert opened this issue Oct 13, 2022 · 9 comments
Open
4 of 6 tasks

[BUG] InaccessibleObjectException: Unable to make field transient #13684

Santobert opened this issue Oct 13, 2022 · 9 comments

Comments

@Santobert
Copy link

Santobert commented Oct 13, 2022

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When I try to generate a python client for the current petstore api, the generator runs into an issue. It seems that this problem is platform dependent. The error occurs on Windows with Java 17, but on Linux with Java 8 everything works fine.

npx @openapitools/openapi-generator-cli generate -i petstore.yaml -g python -o python
[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - No .openapi-generator-ignore file found.
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: python (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'python' is considered stable.
[main] INFO  o.o.c.l.AbstractPythonCodegen - Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE="/usr/local/bin/yapf -i"' (Linux/Mac)
[main] INFO  o.o.c.l.AbstractPythonCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - No .openapi-generator-ignore file found.
[main] INFO  o.o.c.languages.PythonClientCodegen - Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE="/usr/local/bin/yapf -i"' (Linux/Mac)
[main] INFO  o.o.c.languages.PythonClientCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] INFO  o.o.c.languages.PythonClientCodegen - generateAliasAsModel is hard coded to true in this generator. Alias models will only be generated if they contain validations or enums
Exception in thread "main" java.lang.RuntimeException: Could not generate model 'Address'
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:563)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:912)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:465)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: com.github.jknack.handlebars.HandlebarsException: model.handlebars:3:3: java.lang.reflect.InaccessibleObjectException: Unable to make field transient java.util.HashMap$Node[] java.util.HashMap.table accessible: module java.base does not "opens java.util" to unnamed module @3fa77460
    model.handlebars:3:3
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
        at com.github.jknack.handlebars.context.FieldValueResolver$FieldMember.setAccessible(FieldValueResolver.java:150)
        at com.github.jknack.handlebars.context.MemberValueResolver.cache(MemberValueResolver.java:82)
        at com.github.jknack.handlebars.context.MemberValueResolver.resolve(MemberValueResolver.java:54)
        at com.github.jknack.handlebars.Context$CompositeValueResolver.resolve(Context.java:199)
        at com.github.jknack.handlebars.internal.path.PropertyPath.eval(PropertyPath.java:52)
        at com.github.jknack.handlebars.Context$PathExpressionChain.next(Context.java:361)
        at com.github.jknack.handlebars.Context$PathExpressionChain.eval(Context.java:381)
        at com.github.jknack.handlebars.Context.get(Context.java:618)
        at com.github.jknack.handlebars.internal.Partial.override(Partial.java:253)
        at com.github.jknack.handlebars.internal.Partial.merge(Partial.java:226)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:125)
        at com.github.jknack.handlebars.internal.TemplateList.merge(TemplateList.java:95)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:125)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:113)
        at org.openapitools.codegen.templating.HandlebarsEngineAdapter.compileTemplate(HandlebarsEngineAdapter.java:92)
        at org.openapitools.codegen.TemplateManager.write(TemplateManager.java:163)
        at org.openapitools.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:1058)
        at org.openapitools.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:1045)
        at org.openapitools.codegen.DefaultGenerator.generateModel(DefaultGenerator.java:402)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:554)
        ... 4 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field transient java.util.HashMap$Node[] java.util.HashMap.table accessible: module java.base does not "opens java.util" to unnamed module @3fa77460
        ... 28 more
openapi-generator version

6.2.0

OpenAPI declaration file content or url

See https://editor.swagger.io/

petstore.yaml.txt

Generation Details
npx @openapitools/openapi-generator-cli generate -i petstore.yaml -g python -o python
Steps to reproduce
Related issues/PRs
Suggest a fix
@Santobert Santobert changed the title [BUG][Python] InaccessibleObjectException: Unable to make field transient [BUG] InaccessibleObjectException: Unable to make field transient Oct 14, 2022
@lifehackett
Copy link

I am running into the same issue

@aplr
Copy link

aplr commented Oct 31, 2022

I also ran into that issue. Guess sth is kinda hardcoded which should not be, didn't dig too much into the internals. My solution was to just use openjdk 11 instead of the latest one, now it's working.

@JPLachance
Copy link

👋🏼

I got the same issue after installing the openapi-generator CLI using Homebrew this morning.

brew install openapi-generator

Downloading the Jar and running the Jar using openjdk 11 worked.

@Ichimonji10
Copy link
Contributor

Ichimonji10 commented Nov 1, 2022

I'm also afflicted by this issue, on Fedora 36.

The nicest resolution I've found is to set which version of Java is being used:

npm install @openapitools/openapi-generator-cli
"$(npm bin)/openapi-generator-cli" help  # ok
"$(npm bin)/openapi-generator-cli" generate ...  # fail

# pick default java version
update-alternatives --display java
sudo update-alternatives --set java java-11-openjdk.x86_64
"$(npm bin)/openapi-generator-cli" generate ...  # ok

# reset changes
sudo update-alternatives --auto java

@lukeselden
Copy link

lukeselden commented Nov 10, 2022

I managed to get this to work without downgrading java by adapting the answer to this stackoverflow question - I added the --add-opens arguments to my JAVA_OPTS.
set JAVA_OPTS=--add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED

@eddiegroves
Copy link

Thanks @lukeselden for the solution.

If you use direnv:

export JAVA_OPTS="--add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED"                                                                                                

@tloubrieu-jpl
Copy link

I had that error with the brew install 6.3.0, but it works with the 6.3.0-SNAPSHOT that I built from the github repository.

@tiago-peres
Copy link

tiago-peres commented Feb 16, 2023

I've gone through that issue as well after

  1. Install via homebrew:
brew install openapi-generator
  1. Then, generate a ruby client from a valid openapi doc:
openapi-generator generate -i openapi_v0.yaml -g python -o /tmp/test/

bug


Tested with other generators (ruby, python-legacy, ...) and it worked fine

others

@avandecreme
Copy link
Contributor

I investigated a bit and found that handlebars-java should be upgraded to version 4.3 or later.
Unfortunately doing that cause another issue as spotted by @jhannes in jknack/handlebars.java#940

cogwirrel added a commit to aws/aws-pdk that referenced this issue May 15, 2023
Code generation would fail for JDK >11 due to the following issue:

OpenAPITools/openapi-generator#13684

Setting JAVA_OPTS works around this issue, allowing for generation with newer JDKs
agdimech pushed a commit to aws/aws-pdk that referenced this issue May 15, 2023
Code generation would fail for JDK >11 due to the following issue:

OpenAPITools/openapi-generator#13684

Setting JAVA_OPTS works around this issue, allowing for generation with newer JDKs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants