Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
In Java 9, why are package collisions treated a bit differently in some cases?

I am experimenting with Java 9 and looking at the following scenarios:

Experiment 1

  • module A
  • module B
  • both declare a non empty package named com.foo, but do not export it.
  • both are required by a 3rd module C

Running a main from 'C' gives a runtime error:

java.lang.RuntimeException: Package com.foo in both module B and module A

Experiment 2

Same as before but this time both export com.foo.

Result of executing main from C:

java.lang.module.ResolutionException: Modules B and A export package com.foo to module C

Experiment 3

Same as 2, but this time I declared package com.foo in module C.

Now I get a compilation error: Error:(4, 1) java: module C reads package com.foo from both A and B

Why aren't the first two cases not caught during compilation as well? Are there runtime properties I am not aware of that preclude resolution before executing the program?

Also, as far as error messages are concerned: in what way is the error message in experiment 2 better than the one given in experiment 1. It is not that if one of the modules does not export it that the end result will be any different. In other words, what was the consideration behind producing different error messages?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Experiment #2 and #3 are split package issues and should be errors at both compile-time and run-time. For #2 I can't tell from your post why you don't see a compilation error when compiling C. You should see an error with text like "module C reads package com.foo from both A and B".

Experiment #1 is probably A, B, and C on the application module path where they cannot all live in the same name space (same class loader) due to the overlapping packages. The error message you see has been improved a bit in recent builds.

Note that the experiments here have been discussed in many threads on jigsaw-dev and that might be better place to bring up questions and experiences, at least while JDK 9 is still in development.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!