Skip to content

[WIP] Allow IDE enable/disable escaping classpath entries in jars#4843

Open
iloveeclipse wants to merge 1 commit into
eclipse-jdt:masterfrom
iloveeclipse:escape_jar
Open

[WIP] Allow IDE enable/disable escaping classpath entries in jars#4843
iloveeclipse wants to merge 1 commit into
eclipse-jdt:masterfrom
iloveeclipse:escape_jar

Conversation

@iloveeclipse
Copy link
Copy Markdown
Member

Since b74a7b8 JDT Core (but not ecj!) supported Class-Path attribute for external jars and added all entries from such jar to the current project classpath.

This change introduces new JavaCore preference that allows JDT ignore "escaping" classpath entries read from external jars (entries, containing ".." path segment).

By default, JDT disables now old behavior and disallows such paths.

See #258 See https://bugs.eclipse.org/bugs/show_bug.cgi?id=198572

@iloveeclipse iloveeclipse changed the title Allow IDE enable/disable escaping classpath entries in jars [WIP] Allow IDE enable/disable escaping classpath entries in jars Feb 16, 2026
@iloveeclipse iloveeclipse marked this pull request as ready for review February 16, 2026 16:01
Since b74a7b8 JDT Core (but not ecj!)
supported Class-Path attribute for external jars and added all entries
from such jar to the current project classpath.

This change introduces new JavaCore preference that allows JDT ignore
"escaping" classpath entries read from external jars (entries,
containing ".." path segment).

By default, JDT disables now old behavior and disallows such paths.

See eclipse-jdt#258
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=198572
@iloveeclipse
Copy link
Copy Markdown
Member Author

DO NOT MERGE, it is a draft PR.

The only reason it is not "draft" is this: #4844 - I want see test results.

Copy link
Copy Markdown
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

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

Thank you very much for looking into this, @iloveeclipse !

I just have some minor comments.

Also, how do I test this?

Comment on lines +2738 to +2739
* <dt>Default:</dt>
* <dd><code>"disabled"</code></dd>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The JavaDoc is confusing:

This option should be disabled to be consistent with command line compiler, but it is enabled by default for backward compatibility reasons ...

I see that it is DISABLED in JavaCorePreferenceInitializer.

if (JavaCore.DISABLED.equals(escapePref) && calledFileName.indexOf(DOT_DOT) != -1
&& hasDotDot(Path.fromPortableString(calledFileName))) {
if (JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
trace("Invalid (escaping jar directory) Class-Path entry " + calledFileName //$NON-NLS-1$
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NIT: to be able to search the log files more easily (a search for Invalid Class-Path would yield all problems)

Suggested change
trace("Invalid (escaping jar directory) Class-Path entry " + calledFileName //$NON-NLS-1$
trace("Invalid Class-Path entry (escaping jar directory)" + calledFileName //$NON-NLS-1$

String escapePref = JavaCore.getOptions()
.get(JavaCore.CORE_ENABLE_ESACAPING_CP_ENTRIES_IN_JAR_MANIFEST);
if (JavaCore.DISABLED.equals(escapePref) && calledFileName.indexOf(DOT_DOT) != -1
&& hasDotDot(Path.fromPortableString(calledFileName))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question: the JavaDoc of Path.fromPortableString(String) mentions:

The path string must have been produced by a previous call to IPath.toPortableString.

... and also

Instead of calling this method it is recommended to call IPath.fromPortableString(String) instead

w.r.t. 1) I couldn't find any calls to toPortableString in the generation, but I assume it is safe to use this method anyway?

w.r.t. to 2) The code already calls IPath.fromPortableString(...)

Image

so I would simply skip the indirection and call it directly:

Suggested change
&& hasDotDot(Path.fromPortableString(calledFileName))) {
&& hasDotDot(IPath.fromPortableString(calledFileName))) {

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.

2 participants