Skip to content

Commit b780b9f

Browse files
committed
Allow IDE enable/disable escaping classpath entries in jars
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
1 parent 90dce92 commit b780b9f

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,6 +2715,34 @@ public final class JavaCore extends Plugin {
27152715
*/
27162716
public static final String CORE_MAIN_ONLY_PROJECT_HAS_TEST_ONLY_DEPENDENCY = PLUGIN_ID + ".classpath.mainOnlyProjectHasTestOnlyDependency"; //$NON-NLS-1$
27172717

2718+
/**
2719+
* Core option ID: Enable escaping classpath entries in jar manifests (like ../bad.jar).
2720+
* <p>
2721+
* When enabled, the classpath entries in jar manifests can escape current jar directory tree (like
2722+
* ../lib/some.jar). When disabled, all classpath entries in manifest must be inside current jar directory tree.
2723+
* </p>
2724+
* <p>
2725+
* This option should be disabled to be consistent with command line compiler, but it is enabled by default for
2726+
* backward compatibility reasons (in the IDE escaping classpath entries was possible since Eclipse 3.5, see
2727+
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=198572).
2728+
* </p>
2729+
* <p>
2730+
* For performance reasons, any presence of the &quot;..&quot; segment in a classpath entry in a jar manifest will
2731+
* cause the compiler to assume that the entry is escaping the current jar directory tree.
2732+
* </p>
2733+
* <dl>
2734+
* <dt>Option id:</dt>
2735+
* <dd><code>"org.eclipse.jdt.core.classpath.enableEscapingCpEntriesInJarManifest"</code></dd>
2736+
* <dt>Possible values:</dt>
2737+
* <dd><code>{ "enabled", "disabled" }</code></dd>
2738+
* <dt>Default:</dt>
2739+
* <dd><code>"disabled"</code></dd>
2740+
* </dl>
2741+
*
2742+
* @since 3.45
2743+
*/
2744+
public static final String CORE_ENABLE_ESACAPING_CP_ENTRIES_IN_JAR_MANIFEST = PLUGIN_ID + ".classpath.enableEscapingCpEntriesInJarManifest"; //$NON-NLS-1$
2745+
27182746
/**
27192747
* Compiler option ID: Enabling support for preview language features.
27202748
* <p>When enabled, the compiler will activate the preview language features of this Java version.</p>

org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,16 @@ private static void resolvedChainedLibraries(IPath jarPath, HashSet visited, Arr
978978
trace("Invalid Class-Path entry " + calledFileName + " in manifest of jar file: " + jarPath.toOSString()); //$NON-NLS-1$ //$NON-NLS-2$
979979
}
980980
} else {
981+
String escapePref = JavaCore.getOptions()
982+
.get(JavaCore.CORE_ENABLE_ESACAPING_CP_ENTRIES_IN_JAR_MANIFEST);
983+
if (JavaCore.DISABLED.equals(escapePref) && calledFileName.indexOf(DOT_DOT) != -1
984+
&& hasDotDot(Path.fromPortableString(calledFileName))) {
985+
if (JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
986+
trace("Invalid (escaping jar directory) Class-Path entry " + calledFileName //$NON-NLS-1$
987+
+ " in manifest of jar file: " + jarPath.toOSString()); //$NON-NLS-1$
988+
}
989+
continue;
990+
}
981991
IPath calledJar = directoryPath.append(new Path(calledFileName));
982992
// Ignore if segment count is Zero (https://bugs.eclipse.org/bugs/show_bug.cgi?id=308150)
983993
if (calledJar.segmentCount() == 0) {

org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public void initializeDefaultPreferences() {
7878
defaultOptionsMap.put(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, JavaCore.ENABLED);
7979
defaultOptionsMap.put(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.ERROR);
8080
defaultOptionsMap.put(JavaCore.CORE_MAIN_ONLY_PROJECT_HAS_TEST_ONLY_DEPENDENCY, JavaCore.ERROR);
81+
defaultOptionsMap.put(JavaCore.CORE_ENABLE_ESACAPING_CP_ENTRIES_IN_JAR_MANIFEST, JavaCore.DISABLED);
8182

8283
// encoding setting comes from resource plug-in
8384
optionNames.add(JavaCore.CORE_ENCODING);

0 commit comments

Comments
 (0)