Skip to content

Commit

Permalink
Replace an assert with a runtime exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Gene Gleyzer committed Feb 25, 2025
1 parent c00eea1 commit f31ddc7
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions javatools/src/main/java/org/xvm/runtime/template/reflect/xRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,14 @@ private int ensureClassHandle(Frame frame, ObjectHandle hTarget, int iReturn)
{
if (hTarget.getComposition() instanceof ClassComposition clzTarget)
{
// the only way for a handle to be a relational or not shared type is to be
// explicitly masked
assert !clzTarget.isInception();
if (clzTarget.isInception())
{
// the only way for a handle to be a relational or not shared type is to be
// explicitly masked
return frame.raiseException(xException.invalidType(frame, "Type \"" +
type.getValueString() + "\" is not shared with the TypeSystem of module \"" +
frame.f_context.f_container.getModule().getName() + '"'));
}

if (clzTarget.getInceptionType().isShared(pool))
{
Expand Down Expand Up @@ -217,7 +222,8 @@ public String toString()
return ctxOwner.sendOp1Request(frame, opClassHandle, iReturn);
}
}
return frame.raiseException("Unsupported type: " + type.getValueString());
return frame.raiseException(
xException.invalidType(frame, "Unsupported type: " + type.getValueString()));
}

if (type.isImmutabilitySpecified())
Expand Down Expand Up @@ -260,9 +266,18 @@ private int maskClassHandle(Frame frame, ObjectHandle hClass, TypeConstant typeM
listAnno.toArray(Annotation.NO_ANNOTATIONS));
}
}

TypeComposition clzMask = hClass.getTemplate().ensureClass(frame.f_context.f_container, typeClz);
return frame.assignValue(iReturn, hClass.cloneAs(clzMask));
try
{
TypeComposition clzMask = hClass.getTemplate().
ensureClass(frame.f_context.f_container, typeClz);
return frame.assignValue(iReturn, hClass.cloneAs(clzMask));
}
catch (Exception e)
{
return frame.raiseException(
xException.invalidType(frame, "Failed to create a class handle for : " +
typeMask.getValueString()));
}
}

@Override
Expand Down

0 comments on commit f31ddc7

Please sign in to comment.