Skip to content

Commit

Permalink
[JdkInfo] handle invalid XML from /usr/libexec/java_home (#120)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonathanpeppers authored Jun 4, 2021
1 parent 81519fe commit 79e3b97
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,14 @@ static IEnumerable<string> GetLibexecJdkPaths (Action<TraceLevel, string> logger
return;
xml.Append (e.Data);
}, includeStderr: false);
var plist = XElement.Parse (xml.ToString ());

XElement plist;
try {
plist = XElement.Parse (xml.ToString ());
} catch (XmlException e) {
logger (TraceLevel.Warning, string.Format (Resources.InvalidXmlLibExecJdk_path_args_message, jhp.FileName, jhp.Arguments, e.Message));
yield break;
}
foreach (var info in plist.Elements ("array").Elements ("dict")) {
var JVMHomePath = (XNode) info.Elements ("key").FirstOrDefault (e => e.Value == "JVMHomePath");
if (JVMHomePath == null)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,7 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</comment>
</data>
<data name="InvalidXmlLibExecJdk_path_args_message" xml:space="preserve">
<value>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
{0} - The path of the file being read.
{1} - The exception message of the associated exception.</note>
</trans-unit>
<trans-unit id="InvalidXmlLibExecJdk_path_args_message">
<source>An exception occurred while reading the output of '{0} {1}'. Exception: {2}</source>
<target state="new">An exception occurred while reading the output of '{0} {1}'. Exception: {2}</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 79e3b97

Please sign in to comment.