From af482ea053f542944de3d6b4256af917fbf6e5f5 Mon Sep 17 00:00:00 2001 From: Tobias Thierer Date: Fri, 10 Jan 2020 15:56:46 +0000 Subject: [PATCH] Disallow unnamed package on the bootclasspath. There are currently no classes on the bootclasspath that live in the unnamed package (empty package name). This CL explicitly forbids it. This has the side effect of guarding against some classes of bugs, for example R8 has functionality to generate some helper classes in the unnamed package that should not be on the to bootclasspath because they would hide corresponding classes in Applications. Strictly speaking I believe that the "not package_name or " part of the condition in the touched script is not needed because LoadWhitelist() already skips empty lines and doesn't add "^$" to the whitelist regex, but relying on this seems very fragile. If there ever is a need to have classes in the bootclasspath's unnamed package in future then we can always change this again. Bug: 147480264 Test: Treehugger Change-Id: Ic310dd0779dde133b3a5c3039ea5b70d31331a9b --- core/tasks/check_boot_jars/check_boot_jars.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/tasks/check_boot_jars/check_boot_jars.py b/core/tasks/check_boot_jars/check_boot_jars.py index 9d71553c81..67b73d574b 100755 --- a/core/tasks/check_boot_jars/check_boot_jars.py +++ b/core/tasks/check_boot_jars/check_boot_jars.py @@ -53,10 +53,9 @@ def CheckJar(whitelist_path, jar): if f.endswith('.class'): package_name = os.path.dirname(f) package_name = package_name.replace('/', '.') - # Skip class without a package name - if package_name and not whitelist_re.match(package_name): - print >> sys.stderr, ('Error: %s contains class file %s, whose package name %s is not ' - 'in the whitelist %s of packages allowed on the bootclasspath.' + if not package_name or not whitelist_re.match(package_name): + print >> sys.stderr, ('Error: %s contains class file %s, whose package name %s is empty or' + ' not in the whitelist %s of packages allowed on the bootclasspath.' % (jar, f, package_name, whitelist_path)) return False return True