Skip to content

Commit 79e3b97

Browse files
[JdkInfo] handle invalid XML from /usr/libexec/java_home (#120)
Context: dotnet/android#5992 Context: https://dev.azure.com/xamarin/public/_build/results?buildId=40929&view=logs&j=cfef19e4-4225-5e84-636a-86ba2231ac21&t=cd3bc6c3-ac29-5320-67c9-5fb59fc8e05c&l=732 dotnet/maui has hit some build failures such as: error XARSD7000: System.Xml.XmlException: Root element is missing. error XARSD7000: at System.Xml.XmlTextReaderImpl.Throw (System.Exception e) error XARSD7000: at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo (System.String res) error XARSD7000: at System.Xml.XmlTextReaderImpl.ParseDocumentContent () error XARSD7000: at System.Xml.XmlTextReaderImpl.Read () error XARSD7000: at System.Xml.XmlReader.MoveToContent () error XARSD7000: at System.Xml.Linq.XElement.Load (System.Xml.XmlReader reader, System.Xml.Linq.LoadOptions options) error XARSD7000: at System.Xml.Linq.XElement.Parse (System.String text, System.Xml.Linq.LoadOptions options) error XARSD7000: at System.Xml.Linq.XElement.Parse (System.String text) error XARSD7000: at Xamarin.Android.Tools.JdkInfo+<GetLibexecJdkPaths>d__56.MoveNext () error XARSD7000: at System.Linq.Enumerable+DistinctIterator`1[TSource].MoveNext () error XARSD7000: at System.Linq.Enumerable+SelectEnumerableIterator`2[TSource,TResult].MoveNext () error XARSD7000: at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[TSource,TResult].ToArray () error XARSD7000: at System.Linq.Buffer`1[TElement]..ctor (System.Collections.Generic.IEnumerable`1[T] source) error XARSD7000: at System.Linq.OrderedEnumerable`1+<GetEnumerator>d__3[TElement].MoveNext () error XARSD7000: at System.Linq.Enumerable+ConcatIterator`1[TSource].MoveNext () error XARSD7000: at System.Linq.Enumerable+SelectEnumerableIterator`2[TSource,TResult].MoveNext () error XARSD7000: at Xamarin.Android.Tools.AndroidSdkBase.GetValidPath (System.Func`2[T,TResult] pathValidator, System.String ctorParam, System.Func`1[TResult] getPreferredPath, System.Func`1[TResult] getAllPaths) error XARSD7000: at Xamarin.Android.Tools.AndroidSdkBase.Initialize (System.String androidSdkPath, System.String androidNdkPath, System.String javaSdkPath) error XARSD7000: at Xamarin.Android.Tools.AndroidSdkInfo..ctor (System.Action`2[T1,T2] logger, System.String androidSdkPath, System.String androidNdkPath, System.String javaSdkPath) error XARSD7000: at Xamarin.Android.Tasks.MonoAndroidHelper.RefreshAndroidSdk (System.String sdkPath, System.String ndkPath, System.String javaPath, Microsoft.Build.Utilities.TaskLoggingHelper logHelper) error XARSD7000: at Xamarin.Android.Tasks.ResolveSdks.RunTask () error XARSD7000: at Xamarin.Android.Tasks.AndroidTask.Execute () It looks like `JdkInfo.GetLibexecJdkPaths()` doesn't handle `XmlException` and warn appropriately. I don't have the *actual* output of `/usr/libexec/java_home -X` from these machines, but I suspect it's printing some message before the XML or no XML at all.
1 parent 81519fe commit 79e3b97

16 files changed

+85
-1
lines changed

src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,14 @@ static IEnumerable<string> GetLibexecJdkPaths (Action<TraceLevel, string> logger
350350
return;
351351
xml.Append (e.Data);
352352
}, includeStderr: false);
353-
var plist = XElement.Parse (xml.ToString ());
353+
354+
XElement plist;
355+
try {
356+
plist = XElement.Parse (xml.ToString ());
357+
} catch (XmlException e) {
358+
logger (TraceLevel.Warning, string.Format (Resources.InvalidXmlLibExecJdk_path_args_message, jhp.FileName, jhp.Arguments, e.Message));
359+
yield break;
360+
}
354361
foreach (var info in plist.Elements ("array").Elements ("dict")) {
355362
var JVMHomePath = (XNode) info.Elements ("key").FirstOrDefault (e => e.Value == "JVMHomePath");
356363
if (JVMHomePath == null)

src/Xamarin.Android.Tools.AndroidSdk/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Xamarin.Android.Tools.AndroidSdk/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,7 @@
130130
{0} - The path of the file being read.
131131
{1} - The exception message of the associated exception.</comment>
132132
</data>
133+
<data name="InvalidXmlLibExecJdk_path_args_message" xml:space="preserve">
134+
<value>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</value>
135+
</data>
133136
</root>

src/Xamarin.Android.Tools.AndroidSdk/Properties/xlf/Resources.cs.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
{0} - The path of the file being read.
1818
{1} - The exception message of the associated exception.</note>
1919
</trans-unit>
20+
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
21+
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
22+
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
23+
<note />
24+
</trans-unit>
2025
</body>
2126
</file>
2227
</xliff>

src/Xamarin.Android.Tools.AndroidSdk/Properties/xlf/Resources.de.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
{0} - The path of the file being read.
1818
{1} - The exception message of the associated exception.</note>
1919
</trans-unit>
20+
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
21+
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
22+
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
23+
<note />
24+
</trans-unit>
2025
</body>
2126
</file>
2227
</xliff>

src/Xamarin.Android.Tools.AndroidSdk/Properties/xlf/Resources.es.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
{0} - The path of the file being read.
1818
{1} - The exception message of the associated exception.</note>
1919
</trans-unit>
20+
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
21+
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
22+
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
23+
<note />
24+
</trans-unit>
2025
</body>
2126
</file>
2227
</xliff>

src/Xamarin.Android.Tools.AndroidSdk/Properties/xlf/Resources.fr.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
{0} - The path of the file being read.
1818
{1} - The exception message of the associated exception.</note>
1919
</trans-unit>
20+
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
21+
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
22+
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
23+
<note />
24+
</trans-unit>
2025
</body>
2126
</file>
2227
</xliff>

src/Xamarin.Android.Tools.AndroidSdk/Properties/xlf/Resources.it.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
{0} - The path of the file being read.
1818
{1} - The exception message of the associated exception.</note>
1919
</trans-unit>
20+
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
21+
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
22+
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
23+
<note />
24+
</trans-unit>
2025
</body>
2126
</file>
2227
</xliff>

src/Xamarin.Android.Tools.AndroidSdk/Properties/xlf/Resources.ja.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
{0} - The path of the file being read.
1818
{1} - The exception message of the associated exception.</note>
1919
</trans-unit>
20+
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
21+
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
22+
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
23+
<note />
24+
</trans-unit>
2025
</body>
2126
</file>
2227
</xliff>

src/Xamarin.Android.Tools.AndroidSdk/Properties/xlf/Resources.ko.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
{0} - The path of the file being read.
1818
{1} - The exception message of the associated exception.</note>
1919
</trans-unit>
20+
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
21+
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
22+
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
23+
<note />
24+
</trans-unit>
2025
</body>
2126
</file>
2227
</xliff>

0 commit comments

Comments
 (0)