Skip to content

Fix native library filtering for Android ART in Util.java - #5259

Open
1799833473 wants to merge 2 commits into
eclipse-jdt:masterfrom
1799833473:1799833473-patch-1
Open

Fix native library filtering for Android ART in Util.java#5259
1799833473 wants to merge 2 commits into
eclipse-jdt:masterfrom
1799833473:1799833473-patch-1

Conversation

@1799833473

Copy link
Copy Markdown

AI Statement:
This contribution was developed with the assistance of AI tools and has been manually reviewed by me.(including Code)

What it does

Prevents native libraries (.so, .dll, .dylib) from being misidentified as ZIP/JMOD archives or added to the bootclasspath. Fixes #5253.

On Android ART, the bootclasspath may contain native library paths (e.g. /system/lib64/libart.so). ECJ currently treats these as potential ZIP archives because they have an unrecognized file extension, which can lead to unnecessary file probing or classpath pollution.

Changes:

  • Add isNativeLibrary(String) helper with zero-allocation, case-insensitive character comparison (consistent with existing isClassFileName / isJavaFileName style).
  • Filter native libraries in isPotentialZipArchive() → returns false.
  • Filter native libraries in archiveFormat() → returns -1.
  • Exclude native libraries from collectPlatformLibraries() bootclasspath collection, both when parsing sun.boot.class.path / vm.boot.class.path and when scanning javaHome/lib.

How to test

I have pulled the changes from this PR and successfully compiled them locally using the following command:

mvn clean package -DskipTests -T 2 \
  -Dtycho.disableP2Mirrors=false \
  -Dp2.repo.url=https://download.eclipse.org/releases/latest/ \
  -pl org.eclipse.jdt.core.compiler.batch -am

And built locally with:

  mvn clean compile -Pbuild-individual-bundles
  mvn test -Pbuild-individual-bundles

Full test suite was not run locally due to resource constraints (Termux on Android). I rely on CI for complete testing.

Known limitations / Follow-up work

  • Unit tests: No new JUnit tests are included in this PR. Adding tests for isNativeLibrary with various path formats (simple name, absolute path, jar entry path) is recommended as a follow-up.
  • Path separator: isNativeLibrary checks File.separatorChar for directory/extension disambiguation. On Android/Linux (primary target) this is '/' and works correctly for both file-system paths and jar entry paths. Windows paths using '/' as an alternative separator are not explicitly handled; this is consistent with existing methods in Util but could be improved if cross-platform path mixing is a concern.
  • RegionMatches: Character-by-character comparison was chosen to stay consistent with isClassFileName / isJavaFileName and avoid temporary string allocations. String.regionMatches could be considered later for readability without sacrificing performance.

Author checklist

Added a method to check for native library file names and updated bootclasspath handling to exclude native libraries.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves ECJ’s platform/bootclasspath handling by recognizing native library files (.so, .dll, .dylib) and preventing them from being treated as potential ZIP/JMOD archives or added to platform libraries—addressing Android ART bootclasspath entries like /system/lib64/libart.so.

Changes:

  • Added a new native-library filename/path check and used it to exclude native libs from isPotentialZipArchive() and archiveFormat().
  • Filtered native libraries out of collectPlatformLibraries() when reading bootclasspath properties and when scanning javaHome/lib.
Suppressed comments (1)

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/Util.java:736

  • The Javadoc link {@link #isClassFileName} is ambiguous because Util defines both isClassFileName(char[]) and isClassFileName(String). This can produce Javadoc warnings or link to the unintended overload. Please link to a specific signature.
	 * The name may be a simple file name, a file system path, or a jar entry
	 * path. Comparison is done character-by-character to avoid extra string
	 * allocations, consistent with {@link #isClassFileName}.
	 * </p>

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@1799833473

1799833473 commented Aug 1, 2026

Copy link
Copy Markdown
Author

Pull request overview

This PR improves ECJ’s platform/bootclasspath handling by recognizing native library files (, , ) and preventing them from being treated as potential ZIP/JMOD archives or added to platform libraries—addressing Android ART bootclasspath entries like ..so``.dll``.dylib``/system/lib64/libart.so

Changes:

  • Added a new native-library filename/path check and used it to exclude native libs from and .isPotentialZipArchive()``archiveFormat()
  • Filtered native libraries out of when reading bootclasspath properties and when scanning .collectPlatformLibraries()``javaHome/lib

Suppressed comments (1)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Hi @Copilot,

Thanks for the review. I've read the three suggestions, but they are all code quality optimizations (low priority), not functional bugs. Since the core changes work and all tests pass, I'd prefer to keep them as-is for now. If you consider any of them blocking, please let me know and I'll address them.

Otherwise, I'd appreciate it if we could proceed with merging. Thanks for your time!

And thanks to @iloveeclipse for your time too!

Store the result of file.getAbsolutePath() in a local variable to avoid redundant calls, as suggested by Copilot review.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@1799833473

Copy link
Copy Markdown
Author

Hello @iloveeclipse

May I ask for your advice again on whether I should merge this PR?

Thank you for your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

一个关于Util.java的过滤Native库的建议(Proposal to add filtering for native libraries in Util.java)

2 participants