Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2715,6 +2715,34 @@ public final class JavaCore extends Plugin {
*/
public static final String CORE_MAIN_ONLY_PROJECT_HAS_TEST_ONLY_DEPENDENCY = PLUGIN_ID + ".classpath.mainOnlyProjectHasTestOnlyDependency"; //$NON-NLS-1$

/**
* Core option ID: Enable escaping classpath entries in jar manifests (like ../bad.jar).
* <p>
* When enabled, the classpath entries in jar manifests can escape current jar directory tree (like
* ../lib/some.jar). When disabled, all classpath entries in manifest must be inside current jar directory tree.
* </p>
* <p>
* This option should be disabled to be consistent with command line compiler, but it is enabled by default for
* backward compatibility reasons (in the IDE escaping classpath entries was possible since Eclipse 3.5, see
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=198572).
* </p>
* <p>
* For performance reasons, any presence of the &quot;..&quot; segment in a classpath entry in a jar manifest will
* cause the compiler to assume that the entry is escaping the current jar directory tree.
* </p>
* <dl>
* <dt>Option id:</dt>
* <dd><code>"org.eclipse.jdt.core.classpath.enableEscapingCpEntriesInJarManifest"</code></dd>
* <dt>Possible values:</dt>
* <dd><code>{ "enabled", "disabled" }</code></dd>
* <dt>Default:</dt>
* <dd><code>"disabled"</code></dd>
Comment on lines +2738 to +2739
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.

* </dl>
*
* @since 3.45
*/
public static final String CORE_ENABLE_ESACAPING_CP_ENTRIES_IN_JAR_MANIFEST = PLUGIN_ID + ".classpath.enableEscapingCpEntriesInJarManifest"; //$NON-NLS-1$

/**
* Compiler option ID: Enabling support for preview language features.
* <p>When enabled, the compiler will activate the preview language features of this Java version.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,16 @@ private static void resolvedChainedLibraries(IPath jarPath, HashSet visited, Arr
trace("Invalid Class-Path entry " + calledFileName + " in manifest of jar file: " + jarPath.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
}
} else {
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))) {

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$

+ " in manifest of jar file: " + jarPath.toOSString()); //$NON-NLS-1$
}
continue;
}
IPath calledJar = directoryPath.append(new Path(calledFileName));
// Ignore if segment count is Zero (https://bugs.eclipse.org/bugs/show_bug.cgi?id=308150)
if (calledJar.segmentCount() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void initializeDefaultPreferences() {
defaultOptionsMap.put(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, JavaCore.ENABLED);
defaultOptionsMap.put(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.ERROR);
defaultOptionsMap.put(JavaCore.CORE_MAIN_ONLY_PROJECT_HAS_TEST_ONLY_DEPENDENCY, JavaCore.ERROR);
defaultOptionsMap.put(JavaCore.CORE_ENABLE_ESACAPING_CP_ENTRIES_IN_JAR_MANIFEST, JavaCore.DISABLED);

// encoding setting comes from resource plug-in
optionNames.add(JavaCore.CORE_ENCODING);
Expand Down
Loading