Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

277
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda