-
-
Notifications
You must be signed in to change notification settings - Fork 27
ADFA-3364: Skip corrupt JARs during classpath indexing (+ surface to user) #1410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fryanpan
wants to merge
4
commits into
stage
Choose a base branch
from
ADFA-3364-zipexception-corrupt-jar-indexing
base: stage
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2c479e4
ADFA-3364: skip corrupt jars during classpath indexing
fryanpan 1308401
ADFA-3364: add regression test for corrupt-JAR classpath indexing
fryanpan a169ced
ADFA-3364: surface unreadable/corrupt classpath JARs with a recovery …
fryanpan 6c0c0fc
ADFA-3364: add KDoc for docstring coverage (CodeRabbit)
fryanpan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
.../test/java/com/itsaky/androidide/projects/classpath/JarFsClasspathReaderCorruptJarTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * This file is part of AndroidIDE. | ||
| * | ||
| * AndroidIDE is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * AndroidIDE is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.itsaky.androidide.projects.classpath | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import com.itsaky.androidide.javac.services.fs.CachingJarFileSystemProvider | ||
| import com.itsaky.androidide.utils.FileProvider | ||
| import java.io.File | ||
| import java.nio.file.Files | ||
| import org.junit.After | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
| import org.robolectric.annotation.Config | ||
|
|
||
| /** | ||
| * Regression test for ADFA-3364: a corrupt/truncated/zero-byte JAR among the classpath entries | ||
| * must not abort indexing of the remaining (valid) entries. | ||
| * | ||
| * @author Verification Agent (ADFA-3364) | ||
| */ | ||
| @RunWith(RobolectricTestRunner::class) | ||
| @Config(manifest = Config.DEFAULT_VALUE_STRING) | ||
| class JarFsClasspathReaderCorruptJarTest { | ||
|
|
||
| private lateinit var tmpDir: File | ||
| private lateinit var validJar: File | ||
| private lateinit var corruptJar: File | ||
| private lateinit var zeroByteJar: File | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| // The provider caches by normalized path; start clean so prior runs cannot mask behavior. | ||
| CachingJarFileSystemProvider.clearCache() | ||
|
|
||
| tmpDir = Files.createTempDirectory("adfa3364").toFile() | ||
|
|
||
| // A genuinely valid JAR known to contain android.content.Context. | ||
| val sourceAndroidJar = | ||
| FileProvider.testProjectRoot() | ||
| .resolve("app/src/main/resources/android.jar") | ||
| .toFile() | ||
| assertThat(sourceAndroidJar.exists()).isTrue() | ||
|
|
||
| // Copy it to a unique temp path so the FS-provider cache key is distinct per run. | ||
| validJar = File(tmpDir, "valid.jar") | ||
| sourceAndroidJar.copyTo(validJar, overwrite = true) | ||
|
|
||
| // A truncated JAR: take the first 64 bytes of a real JAR. It has the local-file-header | ||
| // signature but no valid end-of-central-directory record -> ZipException on open/walk. | ||
| corruptJar = File(tmpDir, "corrupt.jar") | ||
| val head = sourceAndroidJar.inputStream().use { it.readNBytes(64) } | ||
| corruptJar.writeBytes(head) | ||
|
|
||
| // A zero-byte file with a .jar extension -> also unreadable as a zip. | ||
| zeroByteJar = File(tmpDir, "empty.jar") | ||
| zeroByteJar.writeBytes(ByteArray(0)) | ||
| } | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| CachingJarFileSystemProvider.clearCache() | ||
| tmpDir.deleteRecursively() | ||
| } | ||
|
|
||
| /** | ||
| * On the FIX branch: the corrupt JAR is skipped (ZipException caught) and the valid JAR is still | ||
| * indexed. On the pre-fix baseline: the ZipException from the corrupt JAR propagates out of | ||
| * [JarFsClasspathReader.listClasses] and this test fails with that exception. | ||
| * | ||
| * Corrupt JAR is listed FIRST so that, if the exception aborts the loop, the valid JAR after it | ||
| * never gets indexed either (stronger assertion that indexing did not abort). | ||
| */ | ||
| @Test | ||
| fun corruptJarDoesNotAbortIndexingOfRemainingEntries() { | ||
| val classes = | ||
| JarFsClasspathReader() | ||
| .listClasses(listOf(corruptJar, zeroByteJar, validJar)) | ||
|
|
||
| // The valid JAR after the corrupt ones must have been fully indexed. | ||
| val context = classes.firstOrNull { it.name == "android.content.Context" } | ||
| assertThat(context).isNotNull() | ||
| assertThat(context!!.packageName).isEqualTo("android.content") | ||
|
|
||
| // Sanity: a non-trivial number of classes were indexed from the valid jar. | ||
| assertThat(classes.size).isGreaterThan(100) | ||
| } | ||
|
|
||
| /** | ||
| * The reader must EXPOSE the skipped JARs (not just log them) so the caller can name the offending | ||
| * dependency to the user and offer a recovery path (re-sync) instead of silently dropping symbols. | ||
| */ | ||
| @Test | ||
| fun unreadableJarsAreCollectedForUserReporting() { | ||
| val reader = JarFsClasspathReader() | ||
| reader.listClasses(listOf(corruptJar, zeroByteJar, validJar)) | ||
|
|
||
| val skipped = reader.unreadableJars.map { it.name }.toSet() | ||
| // Both the truncated and the zero-byte JAR are reported... | ||
| assertThat(skipped).containsExactly("corrupt.jar", "empty.jar") | ||
| // ...and the valid JAR is NOT reported as unreadable. | ||
| assertThat(skipped).doesNotContain("valid.jar") | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move user facing string to resource/string.xml