Class in default package causes StringIndexOutOfBoundsException
A class in the default package causes a StringIndexOutOfBoundsException in the following code:
https://github.com/yWorks/yGuard/blob/06fc74781e21bc9dd05ed19aed34bee7eb4a42f0/src/main/java/com/yworks/yguard/ant/PackageSection.java#L68-L79
match.substring(0, slashIndex) gets a slashIndex of -1 from match.lastIndexOf('/')
Obfuscating any JAR with a class in the default package should be enough to reproduce the issue.
Ideally such classes would be handled like other classes. But if they are considered unsupported a clear exception would be appreciated.
Just out of curiosity @bernhardf-ro did you use unnamed classes? This was a recent addition in Java 21, which would place code in the default package. Otherwise, this behaviour is strongly discouraged. I'm saying this, because this code has worked relatively well for over two decades... 😆
Nevermind, it appears unnamed code is placed in the unnamed package. Anyhow - I'm curious as to what your use case is!
We do not have any use-case for classes in the default package. We found this issue purely by accident. However, finding the reason for the exception required looking into the source code. Fixing the exception (as apparently already done) or throwing an exception with clear a message are both equally fine solutions.