Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error detail throwing NPE for cause() #42249

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading