Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Potential Bug with JSON Decoder Swift

I believe I have found a bug in the JSONDecoder. If one tries to decode a JSON object with more than 8 properties, I get an unrecognizable error:

error: Execution was interrupted, reason: EXCBADACCESS (code=1, address=0xe8). The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

This error happens whenever I execute code similar to below:

struct Objects: Codable {
  var NAME1: String?
  var NAME2: String?
  var NAME3: String?
  var NAME4: String?
  var NAME5: String?
  var NAME6: String?
  var NAME7: String?
  var NAME8: String?
  var NAME9: String?
}
let NEWDATA = """
[
{
  "NAME1": "hi",
  "NAME2": "hi",
  "NAME3": "hi",
  "NAME4": "hi",
  "NAME5": "hi",
  "NAME6": "hi",
  "NAME7": "hi",
  "NAME8": "hi",
  "NAME9": "HELLO"
}
]
""".data(using: .utf8)!
let decoder2 = JSONDecoder()
let product2 = try decoder2.decode([Objects].self, from: NEWDATA)
print(product2)

This happens in both the Playground and on the device. Maybe I am doing something wrong but it works when you have only 8 properties in the Objects struct but not when you have 9 or more.

Xcode Version: 12.1

Swift Version: 5.3

Thanks for all your help!

like image 210
TheSlyTurtle Avatar asked Oct 14 '22 23:10

TheSlyTurtle


1 Answers

Noted @TheSlyTurtle that you also raised this JSONDecoder Limit issue on Apple Developer Forums.

Another user Claude31 and myself independently raised feedback on Feedback Assistant. See FB9080056 and FB9393489.

Apple replied on this 27 July 2021 as follows:

Hi Max,

Thanks for your patience, and for your feedback. Please verify whether this is still an issue in Xcode 13 beta. There have been tools updates since this was filed, and this issue is not seen in our tests.

Please test with the latest betas, and then update your feedback report with your results by logging into https://feedbackassistant.apple.com or by using the Feedback Assistant app.

Xcode 13, macOS 12 and iOS 15 Betas and Release Candidates: https://developer.apple.com/download/

If the issue continues, please provide appropriate fresh logs and screen recordings: https://developer.apple.com/bug-reporting/profiles-and-logs/

Please close this report if resolved, or let us know if still an issue for you. Thank you.

Feedback ID 9080056, Playground Execution Abort With Struct On Ninth Property

Do not reply to this email. Please login to Feedback Assistant to view this request.

Both myself and Claude31 stated that as of Xcode 13 beta 4 (13A5201i) this defect no longer manifests.

like image 170
Max MacLeod Avatar answered Nov 03 '22 04:11

Max MacLeod