Encountering a Ghost: What is "unrecognized Attribute name MODULE"?
\nHave 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:
\nunrecognized Attribute name MODULE (class com.sun.tools.javac.util.SharedNameTable$NameImpl)\nYou 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.
\nIn 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+.
In Short: How to Fix It (For the Impatient)
\nIf 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
kotlin {\n jvmToolchain(11) // or 8 if you want old compatibility\n}\n- \n
- Method 3 (Workaround): Add a flag to the compiler: \n
tasks.withType<KotlinCompile> {\n kotlinOptions {\n jvmTarget = "1.8"\n }\n}\nBut if you want to understand why this works — read on. We'll dive into the depths of the Java compiler.
\n\nUnder the Hood: What is com.sun.tools.javac.util.SharedNameTable$NameImpl?
\nLet'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.javainto.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 wordmodule, it creates aNameImplobject. \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\nWhy is MODULE a Special Word?
\nStarting 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.
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\nReal Example: Kotlin + Gradle + Java 11
\nImagine a simple Kotlin project on Gradle. Here is the build.gradle.kts file:
plugins {\n kotlin("jvm") version