I'm not sure if there's an easy way to add a regression test for this bug, or if it's worthwhile given that the issue is mostly cosmetic and the bug is somewhat of an edge case.
In any case, here's a fix for the problem. Following the steps to reproduce described in the previous comment, I now get this error message:
ij> connect 'jdbc:derby:db;dataEncryption=true;bootPassword=abc1234xyz';
ERROR XJ040: Failed to start database 'db' with class loader sun.misc.Launcher$AppClassLoader@18a80d4, see the next exception for details.
ERROR XBCXU: Encryption of an un-encrypted database failed: Exception during creation of file /tmp/db/seg0/n461.dat for container
The ClassCastException is gone. And if ij had called printStackTrace() or otherwise followed the getCause() exception chain (it currently only follows the SQLException.getNextException() chain), it would have shown the underlying exception too:
Caused by: java.io.FileNotFoundException: /tmp/db/seg0/n461.dat (Permission denied)
at java.io.RandomAccessFile.open(Native Method)
... 45 more