Potential Bug with JSON Decoder Swift
Asked Answered
B

1

6

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!

Brannon answered 29/10, 2020 at 20:34 Comment(13)
That's indeed and issue in the Playground but I am not seeing it in the Simulator.Bordello
Works fine for me in a macOS playground using Xcode 12.2 beta and also iOS playgroundBollen
@JoakimDanielson probably your playground is macOSCampfire
I've seen this before with iOS playgroundsCampfire
I can run it in both macOS and iOS playgrounds so most likely it is the Xcode versionBollen
In macOS playgrounds works fine for me also. I was wondering earlier today, why I get this error :)Bordello
working for me as well iOS playground Xcode 12.1Campfire
Well, after one successful run with macOS playgrounds, now works with iOS also.Bordello
And after restarting Xcode 12.1 the bug returns...Bordello
Thank you all for your help @gcharita. I tried it in MacOS playground and it worked and then swapped it back to iOS and that seems to fix the bug in playground.Brannon
Discussed - but not resolved - here: developer.apple.com/forums/thread/665159Schooling
Have submitted a ticket on Feedback Assistant: feedbackassistant.apple.com/feedback/9078075Schooling
Now believe this is unrelated to JSONDecoder. It is the struct initialisation with nine properties that causes the execution abort.Schooling
S
3

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.

Schooling answered 3/8, 2021 at 13:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.