Skip to content

Commit 32c0bd8

Browse files
committed
CLJCLR-197 - Make sure to catch exceptions thrown by ClrTypeSpec2.Parse.
1 parent 0f2ff8d commit 32c0bd8

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

Clojure/Clojure/Lib/ClrTypeSpec2.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,21 @@ void MergeNested(ClrTypeSpec nestedSpec)
540540

541541
#region Parsing
542542

543-
public static ClrTypeSpec Parse(string typeName)
543+
// THis version swallows errors, return null for bad or unknown.
544+
public static ClrTypeSpec Parse(string typename)
545+
{
546+
try
547+
{
548+
return ParseE(typename);
549+
550+
}
551+
catch
552+
{
553+
return null;
554+
}
555+
}
556+
557+
public static ClrTypeSpec ParseE(string typeName)
544558
{
545559
int pos = 0;
546560
if (typeName is null)

Clojure/Clojure/Lib/RT.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,6 +2936,7 @@ internal static Type classForName(string p, Namespace ns, bool canCallClrTypeSpe
29362936

29372937
var parsedTypename = ClrTypeSpec.Parse(p);
29382938

2939+
if (parsedTypename is not null)
29392940
{
29402941
// Split the type name to identify the namespace and simple name.
29412942
// If we get something like
@@ -2946,7 +2947,7 @@ internal static Type classForName(string p, Namespace ns, bool canCallClrTypeSpe
29462947

29472948
string assemblyNameString = null;
29482949

2949-
if (!string.IsNullOrWhiteSpace(parsedTypename.AssemblyName))
2950+
if (!string.IsNullOrWhiteSpace(parsedTypename?.AssemblyName))
29502951
assemblyNameString = parsedTypename.AssemblyName;
29512952
else
29522953
{
@@ -3049,7 +3050,7 @@ internal static Type classForName(string p, Namespace ns, bool canCallClrTypeSpe
30493050
//return ClrTypeSpec2.GetTypeFromName(p, CurrentNSVar.deref() as Namespace);
30503051
//}
30513052

3052-
if (canCallClrTypeSpec)
3053+
if (canCallClrTypeSpec && parsedTypename is not null)
30533054
{
30543055
var t1 = ClrTypeSpec.GetTypeFromParsedName(parsedTypename, ns);
30553056
if (t1 is not null)
@@ -3855,7 +3856,7 @@ static byte[] ReadStreamBytes(Stream stream)
38553856
var len = stream.Length;
38563857
var data = new byte[len];
38573858
int numRead = stream.Read(data, 0, (int)len);
3858-
if ( numRead < len)
3859+
if (numRead < len)
38593860
{
38603861
throw new EndOfStreamException("Could not read entire stream");
38613862
}

0 commit comments

Comments
 (0)