Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8296656: java.lang.NoClassDefFoundError exception on running fully legitimate code #12754

Closed
wants to merge 9 commits into from

Conversation

archiecobbs
Copy link
Contributor

@archiecobbs archiecobbs commented Feb 25, 2023

This bug and a few others fall into the "output file clash" bucket. This is when the compiler thinks it's writing out two separate files, but due to the way the O/S filesystem maps Path's to actual files, it's really writing the same file twice.

This is usually due to case-insensitive filesystems, but can also be due to how a filesystem "normalizes" file names. For example, on MacOS, compiling this class will generate such a clash:

public class Test {
    interface Cafe\u0301 {
    }
    interface Caf\u00e9 {
    }
}

The reason is that \u0301 is the Unicode character "Combining Acute Accent" which means "stick an accent over the previous character". So MacOS normalizes a e followed by a \u0301 into a Unicode \u00e9, that is, é. However, the Java language treats these the two names Cafe\u0301 and Caf\u00e9 as distinct.

It's infeasible to truly "fix" this problem, so we resort here to a salve, which is to add a new compiler flag --detect-output-file-clashes that enables detection of output file clashes. When the flag is enabled, and a clash is detected, an error is immediately thrown. For example, compiling the example above gives this:

$ javac --help-extra
  ...
  --detect-output-file-clashes
        Generate an error if any output file is overwritten during compilation. This can occur, for example,
        on case-insensitive filesystems. This applies to class files, native header files, and source files.
  ...
$ javac --detect-output-file-clashes Test.java
Test.java:4: error: error while writing Café: output file clash: /Users/archie/test/Test$Café.class
    interface Caf\u00e9 {
    ^
1 error

This at least gives people at risk of encountering this problem a way to turn a runtime error into a compile-time error.

Outstanding Questions

  • Is making this optional via an (extended) flag --detect-output-file-clashes the best way to address this?
  • Does the new field BaseFileManager.outputFilesWritten ever need to be cleared? Can the file manager be used for multiple compilations? If so, is there some "reset" step we should hook into?

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires CSR request JDK-8304533 to be approved

Issues

  • JDK-8296656: java.lang.NoClassDefFoundError exception on running fully legitimate code
  • JDK-8287885: Local classes cause ClassLoader error if the type names are similar but not same
  • JDK-8304533: Add new lint flag "output-file-clash" (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/12754/head:pull/12754
$ git checkout pull/12754

Update a local copy of the PR:
$ git checkout pull/12754
$ git pull https://git.openjdk.org/jdk.git pull/12754/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12754

View PR using the GUI difftool:
$ git pr show -t 12754

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/12754.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 25, 2023

👋 Welcome back archiecobbs! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Feb 25, 2023

@archiecobbs The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the compiler compiler-dev@openjdk.org label Feb 25, 2023
@archiecobbs
Copy link
Contributor Author

/solves 8287885

@openjdk
Copy link

openjdk bot commented Feb 25, 2023

@archiecobbs
Adding additional issue to solves list: 8287885: Local classes cause ClassLoader error if the type names are similar but not same.

@archiecobbs
Copy link
Contributor Author

/csr

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Mar 6, 2023
@openjdk
Copy link

openjdk bot commented Mar 6, 2023

@archiecobbs has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@archiecobbs archiecobbs marked this pull request as ready for review March 20, 2023 13:58
@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 20, 2023
@mlbridge
Copy link

mlbridge bot commented Mar 20, 2023

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Mar 27, 2023
Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

@openjdk
Copy link

openjdk bot commented Mar 27, 2023

@archiecobbs This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8296656: java.lang.NoClassDefFoundError exception on running fully legitimate code
8287885: Local classes cause ClassLoader error if the type names are similar but not same

Reviewed-by: vromero

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 76 new commits pushed to the master branch:

  • 80e2d52: 8302558: Editable JComboBox's popup blocks user from seeing characters in Aqua look and feel
  • 6c3b10f: 8303485: Replacing os.name for operating system customization
  • 87b314a: 7093691: Nimbus LAF: disabled JComboBox using renderer has bad font color
  • 2f34687: 8304689: Add hidden option to disable external spec page
  • 6b2f34f: 8304718: GetIntArrayElements should not be passed JNI_FALSE
  • 138cdc9: 8304694: Runtime exception thrown when break stmt is missing
  • 46b0602: 8304547: Remove checking of -Djava.compiler in src/jdk.jdi/share/classes/com/sun/tools/jdi/SunCommandLineLauncher.java
  • 8d423f7: 8304723: Statically allocate global mutexes
  • 2083088: 8304828: Lots of constant static data not declared static const in cpu/x86
  • 0712adc: 7169951: SwingSet2 throws NullPointerException with Nimbus L&F
  • ... and 66 more: https://git.openjdk.org/jdk/compare/42723dcb1862da598092bb499056940d78a8bdac...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@vicente-romero-oracle) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Mar 27, 2023
@vicente-romero-oracle
Copy link
Contributor

tier1-4 green

@archiecobbs
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Mar 27, 2023
@openjdk
Copy link

openjdk bot commented Mar 27, 2023

@archiecobbs
Your change (at version 73ab9af) is now ready to be sponsored by a Committer.

@vicente-romero-oracle
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Mar 27, 2023

Going to push as commit 14b970d.
Since your change was applied there have been 76 commits pushed to the master branch:

  • 80e2d52: 8302558: Editable JComboBox's popup blocks user from seeing characters in Aqua look and feel
  • 6c3b10f: 8303485: Replacing os.name for operating system customization
  • 87b314a: 7093691: Nimbus LAF: disabled JComboBox using renderer has bad font color
  • 2f34687: 8304689: Add hidden option to disable external spec page
  • 6b2f34f: 8304718: GetIntArrayElements should not be passed JNI_FALSE
  • 138cdc9: 8304694: Runtime exception thrown when break stmt is missing
  • 46b0602: 8304547: Remove checking of -Djava.compiler in src/jdk.jdi/share/classes/com/sun/tools/jdi/SunCommandLineLauncher.java
  • 8d423f7: 8304723: Statically allocate global mutexes
  • 2083088: 8304828: Lots of constant static data not declared static const in cpu/x86
  • 0712adc: 7169951: SwingSet2 throws NullPointerException with Nimbus L&F
  • ... and 66 more: https://git.openjdk.org/jdk/compare/42723dcb1862da598092bb499056940d78a8bdac...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Mar 27, 2023
@openjdk openjdk bot closed this Mar 27, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Mar 27, 2023
@openjdk
Copy link

openjdk bot commented Mar 27, 2023

@vicente-romero-oracle @archiecobbs Pushed as commit 14b970d.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@davidalayachew
Copy link

Thanks @archiecobbs and @vicente-romero-oracle

Sorry for having sent this so late, it's hard to keep up with the traffic of the mailing lists. I only found this because I looked up my old JBS submission from last year on a whim.

What's the best way I should go about testing this? I see instructions on how to build the JDK from the source code. Is that the best way? Or are there any prebuilt versions that contain this fix that you all can think of from the top of your head?

Thanks again for your time, help, and patience!
David Alayachew

@davidalayachew
Copy link

And just for context, I am the original submitter of 8287885

@archiecobbs
Copy link
Contributor Author

What's the best way I should go about testing this?

Using whatever your original example was. Or some simple example like this on a case-insensitive filesystem:

public class Test {
    interface Inner {
    }
    interface INNER {
    }
}

I see instructions on how to build the JDK from the source code. Is that the best way?

As far as I know that's the best way... but I could be unaware of pre-built preview images somewhere.

@davidalayachew
Copy link

What's the best way I should go about testing this?

Using whatever your original example was. Or some simple example like this on a case-insensitive filesystem:

public class Test {
    interface Inner {
    }
    interface INNER {
    }
}

I see instructions on how to build the JDK from the source code. Is that the best way?

As far as I know that's the best way... but I could be unaware of pre-built preview images somewhere.

Ok, beautiful. I'll get on that now. Thanks again to you both!

@davidalayachew
Copy link

Finished building the jdk from source and tested the fix. It worked!

Here is a demonstration for those who are following along.

$ cat abc.java
public class abc
{

        public static class XYZ {}
        public static class xyz {}

        public static void main(String[] args)
        {

                System.out.println("abc");

                XYZ a = new XYZ();

                System.out.println("tuv");

                xyz b = new xyz();

                System.out.println("xyz");

        }

}

$ javac abc.java -Xlint:output-file-clash
warning: [output-file-clash] output file written more than once: C:\Users\david\_WORKSPACE\_PROGRAMMING\_JAVA\abc$xyz.class
1 warning

As you can see, if I use the -Xlint warning above, I now get a warning if any of my classes generate the same filename multiple times. This is perfect, as I now know at compile time that this is something to watch out for.

Thank you for fixing this Archie/Vicente!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler compiler-dev@openjdk.org integrated Pull request has been integrated
3 participants