E222: Encoded Package Name

This warning is emitted when a package name contains characters that will be encoded differently on the classpath, which can lead to undefined behavior.

When package names contain characters that need encoding (like spaces, hyphens, or special symbols), they are transformed when written to the file system. For example, p-q becomes p$minusq. This can cause tools to malfunction because the directory names won't match the package names.

Note: The examples below require package statements and cannot be compiled by Scaladoc's snippet compiler.


Example

package `with spaces` {
  class Foo
}

Error

-- [E222] Syntax Warning: example.scala:1:8 ------------------------------------
1 |package `with spaces` {
  |        ^^^^^^^^^^^^^
  |The package name `with spaces` will be encoded on the classpath, and can lead to undefined behaviour.
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | Tools may not handle directories whose names differ from their corresponding package names.
  | For example, `p-q` is encoded as `p$minusq` when written to the file system.
  |
  | Package objects derive their names from the file names, so files such as `myfile.test.scala`
  | or `myfile-test.scala` can produce encoded names for the generated package objects.
  |
  | In this case, the name `with spaces` is encoded as `with$u0020spaces`.
   -----------------------------------------------------------------------------

Solution

Use package names that don't require encoding. Stick to alphanumeric characters and underscores:

package with_spaces {
  class Foo
}

Or use a naming convention that avoids special characters entirely:

package withspaces {
  class Foo
}

When working with files that have special characters in their names (like myfile-test.scala), be aware that the generated package objects will have encoded names. Consider renaming files to avoid this issue.