(long tweet) java.lang.SecurityException: Prohibited package name
Case
Here is a case of stupid error. I started up a new project in IntelliJ IDEA, laying on a Maven archetype. On launching the first unit test, I got the following error:
[java]Cannot instantiate test(s): java.lang.SecurityException: Prohibited package name: java.lalou.jonathan.multiposts[/java]
Quick fix
As you may have noticed, the package name was prefixed with java.
… which is prohibited by the JDK. An immediate fix is to restore a package name not starting with java.
.
The code in the JDK is explicit: the exception with such a message is raised in a unique occasion:
[java] if ((name != null) && name.startsWith("java.")) {
throw new SecurityException
("Prohibited package name: " +
name.substring(0, name.lastIndexOf(‘.’)));
}
[/java]