Skip to content

Commit

Permalink
Merge pull request #42249 from HindujaB/fix-error-detail
Browse files Browse the repository at this point in the history
Fix error detail throwing NPE for `cause()`
  • Loading branch information
warunalakshitha authored Mar 7, 2024
2 parents f3db542 + 3c8ebcd commit 2ce4236
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.ballerina.identifier.Utils;
import io.ballerina.runtime.api.Module;
import io.ballerina.runtime.api.PredefinedTypes;
import io.ballerina.runtime.api.TypeTags;
import io.ballerina.runtime.api.types.ErrorType;
import io.ballerina.runtime.api.types.IntersectionType;
Expand All @@ -34,7 +35,7 @@
*/
public class BErrorType extends BAnnotatableType implements ErrorType {

public Type detailType;
public Type detailType = PredefinedTypes.TYPE_ERROR_DETAIL;
public BTypeIdSet typeIdSet;
private IntersectionType intersectionType = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ public static BError getErrorWithNullDetailNegative2(BString msg) {
ErrorType bErrorType = createErrorType(TypeConstants.ERROR, PredefinedTypes.TYPE_ERROR.getPackage());
return ErrorCreator.createError(bErrorType, msg, null, null);
}

public static BError getNullDetailError(BString msg) {
return ErrorCreator.createError(msg, new NullPointerException("cause for the error"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public function main() {

err = trap error_utils:getDistinctErrorWithNullDetailNegative2("error message");
test:assertValueEqual(err.message(), "error message");

err = error_utils:getNullDetailError("error message");
error? c = err.cause();
test:assertValueEqual(c is (), false);
error cause = <error> c;
test:assertValueEqual(cause.message(), "cause for the error");
}

function testTypeIds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ public function getDistinctErrorWithEmptyDetailNegative2(string msg) returns err
public function getDistinctErrorWithNullDetailNegative2(string msg) returns error = @java:Method {
'class: "org.ballerinalang.nativeimpl.jvm.runtime.api.tests.Errors"
} external;

public function getNullDetailError(string msg) returns error = @java:Method {
'class: "org.ballerinalang.nativeimpl.jvm.runtime.api.tests.Errors"
} external;

0 comments on commit 2ce4236

Please sign in to comment.