Dmitriy Dumanskiy Dmitriy Dumanskiy - 3 years ago 160
Java Question

How to deal with "native" keyword in auto generated module names in Java 9?

My project depends on Netty Epoll transport. Here is dependency:


The auto-generated module name for this dependency is:


And as the
keyword is reserved in Java 9 I can't add this module as a dependency to my project:

module core {
requires netty.transport.native.epoll;

Due to:

module not found: netty.transport.<error>

Additionally the jar tool
reports the following:

Unable to derive module descriptor for:
netty.transport.native.epoll: Invalid module name: 'native' is not a
Java identifier

Are there any workarounds? (except "release correct netty artifact", of course).


As the quick fix for maintainers - you can add next line to build:


Answer Source

Well the solution to this seems to be:-

  • renaming the artifact itself


  • other way possible(I've just observed this and not experimented much with though), uninterruptedly using the same artifact name with a new(different) module name could be by packaging META-INF/MANIFEST.MF of the artifact with an attribute Automatic-Module Name which governs the name of the module to be used by the module descriptor when converted as automatic module.

Since the module declaration defined in the specs as:

A module declaration introduces a module name that can be used in other module declarations to express relationships between modules. A module name consists of one or more Java identifiers (§3.8) separated by "." tokens.

Intersetingly the declarations suggests -

In some cases, the Internet domain name may not be a valid package name. Here are some suggested conventions for dealing with these situations:

  • If the domain name contains a hyphen, or any other special character not allowed in an identifier (§3.8), convert it into an underscore.

  • If any of the resulting package name components are keywords (§3.9), append an underscore to them.

  • If any of the resulting package name components start with a digit, or any other character that is not allowed as an initial character of an identifier, have an underscore prefixed to the component.

But keep in mind as you do so that Underscore is a keyword in Java9

enter image description here

int _;  // is would throw error on javac based out of JDK9
int _native; // works fine
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download