Incorrect assumption on the class name in compile(InputSource input, String name) at

Cheng Jin jincheng at
Fri Oct 22 20:59:07 UTC 2021

Hi there,

The code in compile(InputSource input, String name) at
seems incorrect as follows:

public boolean compile(InputSource input, String name) {
        try {
            // Reset globals in case we're called by compile(ArrayList v);

            // The systemId may not be set, so we'll have to check the URL
            String systemId = null;
            if (input != null) {
                systemId = input.getSystemId();

            // Set the translet class name if not already set
            if (_className == null) {
                if (name != null) {
                else if (systemId != null && !systemId.equals("")) {
                    setClassName(Util.baseName(systemId)); <-------
incorrect here

                // Ensure we have a non-empty class name at this point
                if (_className == null || _className.length() == 0) {
                    setClassName("GregorSamsa"); // default translet name

Specifically, the code above assumes that systemId is something like
"xxx:yyyy" in which case the class name (_className) is
"die.verwandlung.yyy" ("die.verwandlung." is the default package name since
Java11) However,Util.baseName(systemId) returns null when systemId is
something like "xxx:" (empty after ":"), in which case the class name
(_className) ends up with "die.verwandlung." (an invalid class name
inserted in the constant pool of the generated bytecode).

In terms of robustness, the code above should be updated to handle the
situation. e.g.

                else if (systemId != null && !systemId.equals("")) {
                  String baseName = Util.baseName(systemId);
                 if ((baseName != null) && (baseName.length() > 0))
{ <------

which means it should check whether the returned base name from
Util.baseName(systemId) is empty at first before setting the class name;
otherwise, it should use the default class name ("GregorSamsa").

Let me know if any other concern on this fix.

Thanks and Best Regards
Cheng Jin

jincheng at

More information about the jdk-dev mailing list