Skip to content

Fix Java map code generation#267

Open
Aayush10016 wants to merge 2 commits into
accordproject:mainfrom
Aayush10016:fix/issue-265-java-map-codegen
Open

Fix Java map code generation#267
Aayush10016 wants to merge 2 commits into
accordproject:mainfrom
Aayush10016:fix/issue-265-java-map-codegen

Conversation

@Aayush10016

Copy link
Copy Markdown

Summary

Fixes generated Java for Concerto map declarations that use scalar aliases or imported map member types.

The Java visitor now:

  • emits Map<K, V> consistently for map fields, getters, and setters
  • unwraps scalar aliases used as map keys or values, for example SSN -> String
  • avoids importing scalar and map declarations that are not emitted as Java classes
  • imports non-scalar map member types, such as enums, when they are required by generated map fields
  • enables the hr_integration Java compile verification case that was previously skipped for this bug

Validation

  • npm.cmd ci
  • npm.cmd run mocha -- test/codegen/fromcto/java/javavisitor.js
  • npm.cmd run test:verify -- --grep "generated Java"
  • npm.cmd run mocha -- test/codegen/codegen.js
  • npm.cmd run test:verify
  • npm.cmd run lint

npm.cmd test -- --grep JavaVisitor was also attempted, but the repository's global coverage gate still runs for filtered tests, so the focused mocha command above is the valid JavaVisitor test signal.

Fixes #265.

Signed-off-by: Aayush Tiwari <aayushtiwari1001@gmail.com>
@Aayush10016
Aayush10016 marked this pull request as ready for review July 17, 2026 15:05

@apoorv7g apoorv7g left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further Review Required from @mttrbrts and if possible @DianaLease and/or @ekarademir .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aayush10016 Thank you for fixing this issue. Good approach. I wanted to know if there is a workaround to fix this without any breaking changes in the javavisitor.js. I believe this might be a breaking change, @mttrbrts can you please review this when you have, overall it looks good to me.

@mttrbrts mttrbrts left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tag @apoorv7g, I would argue that previously code generation for Java where a model contains Scalars and Maps was totally broken so this is a bug fix, not a breaking change.

There's probably a more elegant way to support scalar constraints in Java, but let's fix the bug first, and we can tighten the codegen another time.

protobuf: 'Empty enum produces invalid Protobuf (enum must have >= 1 item) and scalar map keys (e.g. SSN) are not valid Proto3 map key types',
graphql: 'map types emit invalid GraphQL SDL (key/value field syntax)',
rust: 'map declarations reference scalar key/value types (e.g. SSN, Time) that the Rust visitor does not emit, so cargo check fails',
java: 'map declarations reference scalar key/value types (e.g. SSN, Time) that the Java visitor does not emit, so javac fails',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Java code generation for Concerto map declarations so the generated output compiles when map keys/values involve scalar aliases (e.g., SSN -> String) and when map member types (e.g., enums) must be imported even though the map declaration itself is not emitted as a Java class.

Changes:

  • Generate Map<K, V> consistently for map fields and their getters/setters (eliminating prior type mismatches).
  • Unwrap scalar aliases used as map keys/values when generating Java generic arguments.
  • Avoid importing Concerto scalar/map declarations (which are not emitted as Java types), while adding imports for required non-scalar map member types.
  • Re-enable the Java compile verification case by removing the Java skip reason for the affected fixture.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
lib/codegen/fromcto/java/javavisitor.js Updates Java generation to compute map field/getter/setter types as Map<K,V>, unwrap scalar aliases for map members, and refine import emission.
test/codegen/fromcto/java/javavisitor.js Adds unit tests to assert map accessor signatures use resolved Map<K,V> and that scalar aliases in map members are unwrapped.
test/codegen/__snapshots__/codegen.js.snap Updates expected generated Java to remove invalid imports (scalar/map decls), add required enum imports, and reflect corrected map types in fields/accessors.
test/verification/cases.js Removes the Java skip note for the HR integration verification case now that javac should succeed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Java verification - generated output fails javac

4 participants