Skip to content

Commit 71e586b

Browse files
authored
[class-parse] Ignore module-info.class file. (#1093)
Context: https://repo1.maven.org/maven2/org/jetbrains/annotations/24.0.1/annotations-24.0.1.jar Context: #1096 Some AndroidX packages contain a file called `module-info.class` that uses unsupported `.class` constructs. It contains metadata for [Java Modules][0]. ![image](https://user-images.githubusercontent.com/179295/229861846-cbd04239-9d7b-470b-ae6c-844713009104.png) `class-parse` emits this XML fragment for `module-info.class`: <package name="" jni-name=""> <class abstract="false" deprecated="not deprecated" final="false" name="module-info" jni-signature="Lmodule-info;" source-file-name="module-info.java" static="false" visibility="" /> </package> When we try to process this `<class/>`, `generator` emits the warning: warning BG8605: The Java type '' could not be found (are you missing a Java reference jar/aar or a Java binding library NuGet?) This is neither useful nor actionable. Ignore this file in `class-parse`, until we can properly parse it. TODO: Issue #1096 [0]: https://www.oracle.com/corporate/features/understanding-java-9-modules.html
1 parent a172402 commit 71e586b

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Xamarin.Android.Tools.Bytecode/ClassPath.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,9 @@ public void Load (Stream jarStream, bool leaveOpen = false)
6666

6767
using (var jar = CreateZipArchive (jarStream, leaveOpen)) {
6868
foreach (var entry in jar.Entries) {
69-
if (entry.Length == 0)
69+
if (!ShouldLoadEntry (entry))
7070
continue;
71-
using (var s = entry.Open ()) {
72-
if (!ClassFile.IsClassFile (s) || entry.Name.EndsWith (".jnilib", StringComparison.OrdinalIgnoreCase))
73-
continue;
74-
}
71+
7572
using (var entry_stream = entry.Open ())
7673
using (var s = new BufferedStream (entry_stream)) {
7774
try {
@@ -86,6 +83,22 @@ public void Load (Stream jarStream, bool leaveOpen = false)
8683
}
8784
}
8885

86+
static bool ShouldLoadEntry (ZipArchiveEntry entry)
87+
{
88+
if (entry.Length == 0)
89+
return false;
90+
91+
if (entry.Name == "module-info.class")
92+
return false;
93+
94+
if (entry.Name.EndsWith (".jnilib", StringComparison.OrdinalIgnoreCase))
95+
return false;
96+
97+
using var s = entry.Open ();
98+
99+
return ClassFile.IsClassFile (s);
100+
}
101+
89102
static ZipArchive CreateZipArchive (Stream jarStream, bool leaveOpen)
90103
{
91104
var encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false);

0 commit comments

Comments
 (0)