Title: Support Kotlin null safety · Issue #1257 · UnitTestBot/UTBotJava · GitHub
Open Graph Title: Support Kotlin null safety · Issue #1257 · UnitTestBot/UTBotJava
X Title: Support Kotlin null safety · Issue #1257 · UnitTestBot/UTBotJava
Description: Description We have to properly handle Kotlin nullable and not-nullable types to produce correct tests: We shouldn't generate models in which value of not-nullable type is null We should put ?. and !! in generated files where it is neede...
Open Graph Description: Description We have to properly handle Kotlin nullable and not-nullable types to produce correct tests: We shouldn't generate models in which value of not-nullable type is null We should put ?. and...
X Description: Description We have to properly handle Kotlin nullable and not-nullable types to produce correct tests: We shouldn't generate models in which value of not-nullable type is null We should put ?....
Opengraph URL: https://github.com/UnitTestBot/UTBotJava/issues/1257
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support Kotlin null safety","articleBody":"**Description**\r\n\r\nWe have to properly handle Kotlin nullable and not-nullable types to produce correct tests:\r\n\r\n1. We shouldn't generate models in which value of not-nullable type is `null`\r\n2. We should put `?.` and `!!` in generated files where it is needed.\r\n3. We should properly handle possibly-null values returned by java code.\r\n\r\nThere were some attempts to support this, but this is only partially supported currently.\r\n\r\n**To Reproduce**\r\n\r\nThere are many cases where behavior is incorrect. For example, launch action on the following class:\r\n\r\n```Kotlin\r\nclass NullabilityIssuesExample(var x: Int) {\r\n fun copyWithX(new_x: Int?): NullabilityIssuesExample? {\r\n if (new_x == null)\r\n return null\r\n return NullabilityIssuesExample(x + new_x)\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior**\r\n\r\nCorrect tests are generated.\r\n\r\n**Actual behavior**\r\n\r\nAmong others, the following test is generated:\r\n\r\n```Kotlin\r\nfun testCopyWithX2() {\r\n val nullabilityIssuesExample = NullabilityIssuesExample(-255)\r\n val new_x = -255\r\n \r\n val actual = nullabilityIssuesExample.copyWithX(new_x)\r\n \r\n val expected = NullabilityIssuesExample(0)\r\n expected.x = -510\r\n val expectedX = expected.x\r\n val actualX = actual.x\r\n assertEquals(expectedX, actualX) \r\n}\r\n```\r\n\r\n**Additional context**\r\n\r\nThis is an old big issue, which may be solved step by step.\r\n","author":{"url":"https://github.com/volivan239","@type":"Person","name":"volivan239"},"datePublished":"2022-10-28T13:39:32.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1257/UTBotJava/issues/1257"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1a128b5d-6123-dd15-89e4-80c48d694873 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9086:13FE41:1317E9C:185D3EE:69902EC9 |
| html-safe-nonce | 79673bf260ffaa2839e8f2f21839a1ea385e83bbfd051edffbac76563fa4f3e4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDg2OjEzRkU0MToxMzE3RTlDOjE4NUQzRUU6Njk5MDJFQzkiLCJ2aXNpdG9yX2lkIjoiNTc0OTg4OTUzMDg3NTM1ODkyMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cda41852199344e23918e9371fae83408206b03ccb887a99a948efa8888c7196 |
| hovercard-subject-tag | issue:1427280913 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/UnitTestBot/UTBotJava/1257/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2baa41d3984e85cecd74148ed8f59eb0117f9a5af242936d243640c2a439fc24/UnitTestBot/UTBotJava/issues/1257 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2baa41d3984e85cecd74148ed8f59eb0117f9a5af242936d243640c2a439fc24/UnitTestBot/UTBotJava/issues/1257 |
| og:image:alt | Description We have to properly handle Kotlin nullable and not-nullable types to produce correct tests: We shouldn't generate models in which value of not-nullable type is null We should put ?. and... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | volivan239 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b |
| turbo-cache-control | no-preview |
| go-import | github.com/UnitTestBot/UTBotJava git https://github.com/UnitTestBot/UTBotJava.git |
| octolytics-dimension-user_id | 87413538 |
| octolytics-dimension-user_login | UnitTestBot |
| octolytics-dimension-repository_id | 480810501 |
| octolytics-dimension-repository_nwo | UnitTestBot/UTBotJava |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 480810501 |
| octolytics-dimension-repository_network_root_nwo | UnitTestBot/UTBotJava |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3b33c5aedc9808f45bc5fcf0b1e4404cf749dac7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width