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

No architectural violation reported when referring to constants in another module #831

Closed
SuryaEnjarapu opened this issue Sep 20, 2024 · 4 comments
Assignees
Labels
in: core Core module meta model meta: waiting for feedback Waiting for feedback of the original reporter

Comments

@SuryaEnjarapu
Copy link

Able to use constants from another module thats present submodule/package. while executing verify() its does throwing any violations, is it right behavior?

@odrotbohm
Copy link
Member

Can you provide a minimal sample? Not that the JVM usually inlines references to static final fields of primitives and Strings (see this ticket in ArchUnit), so that — technically, when inspecting the byte code — the referring class does not have a dependency on the target one.

@odrotbohm odrotbohm changed the title Able To use constants from another module No architectural violation reported when referring to constants in another module Sep 20, 2024
@odrotbohm odrotbohm self-assigned this Sep 20, 2024
@odrotbohm odrotbohm added in: core Core module meta model meta: waiting for feedback Waiting for feedback of the original reporter labels Sep 20, 2024
@SuryaEnjarapu
Copy link
Author

SuryaEnjarapu commented Sep 25, 2024

"Hi, I'm still encountering this issue in a company project (which I cannot share). However, I tested the same scenario using an example from SivaLabs with Spring Modulith, and it worked as expected. The main differences are that I'm using Java 17 with Spring Modulith 1.2.2, while the SivaLabs example uses Java 21 with Spring Modulith 1.3. I don't believe these differences are causing the issue; it might be related to environment or dependency issues.
@sivaprasadreddy
Please refer to the screenshot of my scenario, where it’s working as expected."

In this below example, I a directly trying use the InventoryConstants in common module
image

@odrotbohm
Copy link
Member

As described above, this is a side effect of the JVM inlining the constants. In other words, the compiled code does not contain that reference. Things might look different if you rather expose the constant as a method, though.

@SuryaEnjarapu
Copy link
Author

Ok Thank you for the response, will try to figure out and update here if i found solution or root cause. Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Core module meta model meta: waiting for feedback Waiting for feedback of the original reporter
Projects
None yet
Development

No branches or pull requests

2 participants