Unrecognized Attribute Name MODULE in Kotlin: Error Analysis

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Encountering a Ghost: What is "unrecognized Attribute name MODULE"?

\n

Have you ever seen an error that feels mystical? Imagine: you're writing in modern Kotlin, everything is flying, Gradle is humming, and suddenly — bam! — something like this appears in the logs:

\n
unrecognized Attribute name MODULE (class com.sun.tools.javac.util.SharedNameTable$NameImpl)
\n

You Google it, find Stack Overflow with thousands of views, and realize: this is not just a bug. This is a compatibility error between worlds. Between Java and Kotlin. Between the old build system and the new modular world.

\n

In this article, we won't just provide a solution. We'll look under the hood of the Java compiler, break down what SharedNameTable is, why the JVM complains about the word MODULE, and how it relates to your Kotlin project. Spoiler: it's not Kotlin's fault, but rather an old Gradle and Java 9+.

\n\n

In Short: How to Fix It (For the Impatient)

\n

If you need to fix the build urgently, here are three working methods. Choose based on your situation:

\n
    \n
  • Method 1 (Recommended): Update Gradle to version 7.0+ and the Kotlin Gradle Plugin to 1.5+. This will solve the problem permanently.
  • \n
  • Method 2 (Quick Fix): Explicitly set the JVM target in build.gradle.kts:
  • \n
\n
kotlin {\n    jvmToolchain(11) // or 8 if you want old compatibility\n}
\n
    \n
  • Method 3 (Workaround): Add a flag to the compiler:
  • \n
\n
tasks.withType<KotlinCompile> {\n    kotlinOptions {\n        jvmTarget = "1.8"\n    }\n}
\n

But if you want to understand why this works — read on. We'll dive into the depths of the Java compiler.

\n\n

Under the Hood: What is com.sun.tools.javac.util.SharedNameTable$NameImpl?

\n

Let's break down this scary string piece by piece. It's not just a random set of words — it points to a specific class inside the Java Development Kit (JDK).

\n
    \n
  • com.sun.tools.javac — the package of the internal Java compiler (javac). Yes, the one that turns .java into .class.
  • \n
  • util.SharedNameTable — a utility class that stores names (variables, methods, classes) in a string pool for optimization. It's a cache to avoid creating a million identical strings.
  • \n
  • $NameImpl — an inner class representing a specific name. When the compiler encounters the word module, it creates a NameImpl object.
  • \n
\n

And now the most interesting part: the error occurs when javac encounters the MODULE attribute in a class file but doesn't know what to do with it. This happens if you are using an old compiler (< Java 9) or, conversely, a new compiler but an old class file format.

\n\n

Why is MODULE a Special Word?

\n

Starting with Java 9, the language introduced the module system (Project Jigsaw). The keyword module became reserved. New attributes appeared in class files: Module, ModulePackages, ModuleMainClass, etc.

\n

When the Kotlin compiler generates bytecode, it can accidentally (or intentionally) add this attribute if your JVM target is set to 9+. And an old Gradle or Maven, using an outdated version of javac, does not understand these attributes. Hence the error.

\n\n

Real Example: Kotlin + Gradle + Java 11

\n

Imagine a simple Kotlin project on Gradle. Here is the build.gradle.kts file:

\n
plugins {\n    kotlin("jvm") version                

Blogs

Book Recommendations