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

Error: attempt to invoke virtual method boolean on a null object reference react native #1403

Closed
1 of 2 tasks
Omerrj opened this issue Nov 14, 2020 · 15 comments
Closed
1 of 2 tasks
Labels
bug Something isn't working
Milestone

Comments

@Omerrj
Copy link

Omerrj commented Nov 14, 2020

Note: for support questions, please use one of these channels: stackoverflow or slack

For bug reports and feature requests for the Swift client, please open an issue there.

For bug reports and feature requests for the Java client, please open an issue there.

You want to:

  • report a bug
  • request a feature

Current behaviour

What is actually happening?

After upgrade from 2.3.0 to 3.0.1 getting error in react-native

Steps to reproduce (if the current behaviour is a bug)

-Create new react-native project.
-Install socket.io-client.
-Use it in your code.

Note: the best way (and by that we mean the only way) to get a quick answer is to provide a failing test case by forking the following fiddle.

Expected behaviour

What is expected?

To work properly.

Setup

  • OS: Android
    Screenshot_1605346335

  • browser:

  • socket.io version: 3.0.1

Other information (e.g. stacktraces, related issues, suggestions how to fix)

@r-julien
Copy link

I have the same issue with my react native project, it's working well on iOS but I get this error with android.

versions:
"react-native": "0.63.3",
"socket.io-client": "^3.0.1",

The error comes during the connection:
io.connect('http://192.168.1.81:3750');

Still trying to understand.

@Mohamed-Rajab-2112
Copy link

me too facing same issue after upgrading my libs, all the app works fine, but socket throw this same error:

versions:
"react-native": "0.63.3",
"socket.io-client": "^3.0.1",

@ChrisBriant
Copy link

I'm new to react-native and I'm also experiencing this issue, is there a known work around?

socket.io-client@3.0.1

@r-julien
Copy link

I downgraded to version 2.3.1, that fixes the issue.

yarn add socket.io-client@2.3.1

@darrachequesne
Copy link
Member

Hi everyone. I could indeed reproduce.

Is there a way we can find the line that is triggering this error?

@darrachequesne darrachequesne added the bug Something isn't working label Nov 16, 2020
darrachequesne added a commit to socketio/engine.io-client that referenced this issue Nov 16, 2020
The undefined value breaks React Native on Android with a rather cryptic error message:

```
Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue() on a null object reference
```

This bug was introduced by [1].

[1]: 5f47a50

Related: socketio/socket.io-client#1403
@Mohamed-Rajab-2112
Copy link

@darrachequesne I read your commit and added
{withCredentials: false}
in socket configs and it works, so the code would be like this:
io(SOCKET_URL, { withCredentials: false, })

@darrachequesne
Copy link
Member

@Mohamed-Rajab-2112 you are right, explicitly setting withCredentials should work 👍

It should be fixed by engine.io-client@4.0.3 (which is included in socket.io-client@3.0.x). Could you please confirm?

I updated the React Native example with Socket.IO v3 here: https://github.com/socketio/socket.io/tree/master/examples/react-native

@Rc85
Copy link

Rc85 commented Nov 17, 2020

I'm having the same issue but only for my RN project in Typescript. My other RN project written in JS doesn't have this issue. And { withCredentials: false } is not an option in SocketClient.Socket.

@Mohamed-Rajab-2112
Copy link

@Rc85

I'm having the same issue but only for my RN project in Typescript. My other RN project written in JS doesn't have this issue. And { withCredentials: false } is not an option in SocketClient.Socket.

Yes you are right, withCredentials is not part of config interface however, I think you should solve this as typescript issue, but try to ignore the ts error just for test sake if this solution would work with you or not.

for typescript, you may try to extend the socket config and add withCredentials to it, just to make typescript not complaining.

@Rc85
Copy link

Rc85 commented Nov 17, 2020

Adding the withCredentials stopped the error, but I cannot connect to my server. On my server, it shows the connection coming in and console log is spammed with reconnection

io.on('connection', (socket) => {
  console.log('Connecting');
}

but on client side, connected is false.

{"_callbacks": {"$connecting": [[Function onConnecting]]}, "acks": {}, "connected": false, "disconnected": true, "flags": {}, "ids": 0, "io": {"_autoConnect": true, "_callbacks": {"$close": [Array], "$open": [Array], "$packet": [Array]}, "_randomizationFactor": 0.5, "_readyState": "opening", "_reconnection": true, "_reconnectionAttempts": Infinity, "_reconnectionDelay": 1000, "_reconnectionDelayMax": 5000, "_timeout": 20000, "backoff": {"attempts": 0, "factor": 2, "jitter": 0.5, "max": 5000, "ms": 1000}, "connecting": [[Circular]], "decoder": {}, "encoder": {}, "engine": {"_callbacks": [Object], "hostname": "10.0.0.100", "id": null, "opts": [Object], "pingInterval": null, "pingTimeout": null, "pingTimeoutTimer": null, "port": "80", "prevBufferLen": 0, "readyState": "opening", "secure": false, "transport": [XHR], "transports": [Array], "upgrades": null, "writeBuffer": [Array]}, "nsps": {"/": [Circular]}, "opts": {"hostname": "10.0.0.100", "path": "/socket.io", "port": "80", "secure": false, "withCredentials": false}, "skipReconnect": false, "subs": [[Object], [Object], [Object]], "uri": "http://10.0.0.100"}, "nsp": "/", "receiveBuffer": [], "sendBuffer": [], "subs": [{"destroy": [Function destroy]}, {"destroy": [Function destroy]}, {"destroy": [Function destroy]}]}

I tried downgrading to 2.3.1 but cannot start my RN project's metro server because of module ../util in node_modules\engine.io-client\lib\transports\polling-xhr.js cannot be resolved. Didn't have this issue with my RN project written in JS, if that matters.

I opened an issue in engine.io-client's repo.

@Mohamed-Rajab-2112
Copy link

@darrachequesne so to test it, should I npm uninstall socket.io-client and run npm install socket.io-client to get the latest update ?

@Mohamed-Rajab-2112
Copy link

Adding the withCredentials stopped the error, but I cannot connect to my server. On my server, it shows the connection coming in and console log is spammed with reconnection

io.on('connection', (socket) => {
  console.log('Connecting');
}

but on client side, connected is false.

{"_callbacks": {"$connecting": [[Function onConnecting]]}, "acks": {}, "connected": false, "disconnected": true, "flags": {}, "ids": 0, "io": {"_autoConnect": true, "_callbacks": {"$close": [Array], "$open": [Array], "$packet": [Array]}, "_randomizationFactor": 0.5, "_readyState": "opening", "_reconnection": true, "_reconnectionAttempts": Infinity, "_reconnectionDelay": 1000, "_reconnectionDelayMax": 5000, "_timeout": 20000, "backoff": {"attempts": 0, "factor": 2, "jitter": 0.5, "max": 5000, "ms": 1000}, "connecting": [[Circular]], "decoder": {}, "encoder": {}, "engine": {"_callbacks": [Object], "hostname": "10.0.0.100", "id": null, "opts": [Object], "pingInterval": null, "pingTimeout": null, "pingTimeoutTimer": null, "port": "80", "prevBufferLen": 0, "readyState": "opening", "secure": false, "transport": [XHR], "transports": [Array], "upgrades": null, "writeBuffer": [Array]}, "nsps": {"/": [Circular]}, "opts": {"hostname": "10.0.0.100", "path": "/socket.io", "port": "80", "secure": false, "withCredentials": false}, "skipReconnect": false, "subs": [[Object], [Object], [Object]], "uri": "http://10.0.0.100"}, "nsp": "/", "receiveBuffer": [], "sendBuffer": [], "subs": [{"destroy": [Function destroy]}, {"destroy": [Function destroy]}, {"destroy": [Function destroy]}]}

I tried downgrading to 2.3.1 but cannot start my RN project's metro server because of module ../util in node_modules\engine.io-client\lib\transports\polling-xhr.js cannot be resolved. Didn't have this issue with my RN project written in JS, if that matters.

I opened an issue in engine.io-client's repo.

Okay, i will give it a check later tonight :)

@Rc85
Copy link

Rc85 commented Nov 17, 2020

Temporary fix at the moment, for me at least is downgrading socket.io-client to 2.3.1. However, engine.io-client raised the mentioned error because its' looking for the ../util module somewhere, which doesn't exist in engine.io-client version 3.4.4. I had to do npm install engine.io-client@latest to resolve the error.

Now I can connect to my server. Gonna stick with 2.3.1 for now.

@Mohamed-Rajab-2112
Copy link

@Rc85 Guys just updated the package few hours ago, try the new version i think it solved the issue, good luck!

@darrachequesne
Copy link
Member

This should be fixed by socketio/engine.io-client@ccb99e3.

Please run npm install socket.io-client@3 to force the update of the dependencies (or npm update --depth 9999 engine.io-client).

If you use Expo, you may have to clear its cache with expo start --clear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants