facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.75k stars 24.29k forks source link

NSNull Length exception thrown while invoking multiSet on target AsyncLocalStorage - unhandled exception crashes app on iOS #16808

Closed ZachCurtis closed 6 years ago

ZachCurtis commented 6 years ago

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment: OS: Win 10 1703 OS Build: 15063.674 Node: 4.6.1 Yarn: -- npm: 5.5.1 Watchman: -- Xcode: -- Android Studio: --

"expo": "^22.0.2",
"react": "16.0.0-beta.5",
"react-native": "^0.49.5",
"react-native-auth0": "^1.2.1",
"react-native-canvas": "^0.1.20",
"react-native-maps": "^0.17.1",
"react-navigation": "^1.0.0-beta.19"

Target Platform: iOS (11)

Steps to Reproduce

NSNull unhandled exception leading to total application crash when attempting to call AsyncStorage.setItem('justAString').

Cannot try/catch/finally to prevent crash, suggest adding exception handler.

Expected Behavior

An error message should have been thrown with the promise associated with setItem.

Actual Behavior

Expo displays this exception and stack trace for less than a second before crashing the Expo instance. image

Reproducible Demo

import React, { Component } from 'react';
import { AsyncStorage } from 'react-native';

replaceLocal('StringParam')

export async function replaceLocal(key,newObj){
    try {
        let stringObject = JSON.stringify(newObj)
        AsyncStorage.setItem(key,stringObject)
    } catch (error) {
        console.log(error)
    }
}
stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

adricos commented 6 years ago

Is it possible to reopen this bug? We are facing a similar issue. (react-native 0.51)

andyh2 commented 6 years ago

We eliminated this issue in our RN codebase at comma.ai by ensuring we never setItem(key, null).

Not sure if this qualifies as a bug given the AsyncStorage.setItem is documented to expect a non-null string value parameter.

ganoch commented 6 years ago

still a problem on setItem on existing key

cbartondock commented 6 years ago

I am having this exact same issue. I already check that the value being stored isn't null

hellgirl commented 6 years ago

Same here. It works fine when loading build in expo but fails in TestFlight. Values are empty strings.

niraj002 commented 6 years ago

I am having this same issue while storing a json file in the async and then using it later. Is there any way to get past this

lsmolic commented 6 years ago

same issue as @niraj002 . I can't store json. Throws the same error

yuoppp commented 6 years ago

The issue is still present.

sewign commented 6 years ago

Issue still present

LipeEng commented 6 years ago

Issue still present.

lubnaski commented 5 years ago

Facing the same issue. Anyone can help?

tmswartz12 commented 5 years ago

I am experiencing the same issue!

ShamarYarde commented 5 years ago

For anyone still experiencing the same problem, check all parameters being password to the setItem method. An example of where the problem could occur would be calling a reducer from another reducer. A mistake would be to access a payload's prop inside the first reducer and then attempt to access a non-existent prop within the reducer being called.

@ZachCurtis You are calling the replaceLocal function with one parameter when it requires two. If you console.log(newObj), you will see that it is undefined.

Zopitirik commented 5 years ago

hi,

using JSON.stringify(value) solved my problem.

AsyncStorage.setItem("myKey", JSON.stringify("myValue"));