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

[Bug]: java.lang.NullPointerException Using Unit Test #41429

Closed
ortegafull87 opened this issue Sep 22, 2023 · 4 comments
Closed

[Bug]: java.lang.NullPointerException Using Unit Test #41429

ortegafull87 opened this issue Sep 22, 2023 · 4 comments

Comments

@ortegafull87
Copy link

ortegafull87 commented Sep 22, 2023

Description

I'am Usign wso2 Microgateway and I considering use unit test in my interceptors, The problem is that migro-gw buil it scan unit test annoted with @test:Config{} but when it compile an error is throwed by ballerina-internal.log file

this is the out:
[2023-09-21 18:59:10,583] SEVERE {b7a.log.crash} - null java.lang.NullPointerException at org.ballerinalang.packerina.task.RunTestsTask.createTestJson(RunTestsTask.java:242) at org.ballerinalang.packerina.task.RunTestsTask.execute(RunTestsTask.java:161) at org.ballerinalang.packerina.TaskExecutor.executeTasks(TaskExecutor.java:38) at org.ballerinalang.packerina.cmd.TestCommand.execute(TestCommand.java:404) at java.util.Optional.ifPresent(Optional.java:159) at org.ballerinalang.tool.Main.main(Main.java:57)

This happened on ballerina project too obviously with same ballerina version 1.2.13

I've used bal dist use command with 1.2.13 version On macOs 13.5.2 (22G91) version with Intel Processor.
and testerina-assertions/testerina_assertions.bal file has source code.

On ballerina project i'am usign this tree file system structure:
Captura de pantalla 2023-09-21 a la(s) 18 20 30

And testerina_assertions.ba is:

Captura de pantalla 2023-09-21 a la(s) 18 22 06

Please There's no any documentation how to do unit test for 1.2.13 ballerina versions, how can I fix this issue.

[2023-09-21 18:59:10,583] SEVERE {b7a.log.crash} - null java.lang.NullPointerException

Steps to Reproduce

➜ sdk use java 8.322.06.2-amzn
We periodically need to update the local cache. Please run:

$ sdk update

Using java version 8.322.06.2-amzn in this shell.

victorortega ~/D/M/ballerina-pocs ""@""/"" last: 0m 0s
➜ bal --version
jBallerina 1.2.13
Language specification 2020R1
Update Tool 1.3.13

victorortega ~/D/M/ballerina-pocs ""@""/"" last: 0m 0s
➜ bal test -a
Compiling source
victorortega/tests:0.1.0

Creating balos
target/balo/tests-2020r1-any-0.1.0.balo

Running Tests
ballerina: Oh no, something really went wrong. Bad. Sad.

There should be a file named "ballerina-internal.log" in the current directory.
If you are able to share with us the code that broke Ballerina then
we would REALLY appreciate if you would report this to us:
go to https://github.com/ballerina-platform/ballerina-lang/issues and
create a bug report with both this log file and the sample code.

We thank you for helping make us better dancers.

Affected Version(s)

ballerina: 1.2.13

OS, DB, other environment details and versions

ballerina: 1.2.13

Related area

-> Compilation
-> Test

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Sep 22, 2023
@ortegafull87 ortegafull87 changed the title [Bug]: SEVERE {b7a.log.crash} - null java.lang.NullPointerException [Bug]: SEVERE {b7a.log.crash} - null java.lang.NullPointerException Using Unit Test Sep 22, 2023
@ortegafull87 ortegafull87 changed the title [Bug]: SEVERE {b7a.log.crash} - null java.lang.NullPointerException Using Unit Test [Bug]: java.lang.NullPointerException at at org.ballerinalang.packerina.task.RunTestsTask.createTestJson.createTestJson(RunTestsTask.java:242) Using Unit Test Sep 22, 2023
@ortegafull87 ortegafull87 changed the title [Bug]: java.lang.NullPointerException at at org.ballerinalang.packerina.task.RunTestsTask.createTestJson.createTestJson(RunTestsTask.java:242) Using Unit Test [Bug]: java.lang.NullPointerException Using Unit Test Sep 22, 2023
@anupama-pathirage anupama-pathirage added Area/TestFramework and removed needTriage The issue has to be inspected and labeled manually labels Oct 5, 2023
@Dilhasha
Copy link
Contributor

Dilhasha commented Oct 6, 2023

@ortegafull87
Can you please share the content within the main.bal file as well?

@Dilhasha
Copy link
Contributor

Dilhasha commented Oct 6, 2023

I had a look again and noticed that you haven't created a module inside the ballerina project.
Within the src there needs to be a module before including tests. The structure should be similar to the following.

image

Without a module, I was able to reproduce the NPE you mentioned and was able to resolve it by adding a module.

@azinneera
Copy link
Contributor

Closing since the solution is provided. Please feel free to reopen if the issue still persists.

Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants