Skip to content

Commit 3f0cffe

Browse files
author
magiclu550
committed
[proxy] fix null npe
1 parent 8682951 commit 3f0cffe

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

jsmod2/NetworkHandler.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Net.Sockets;
44
using System.Reflection;
5+
using System.Text;
56
using jsmod2;
67
using jsmod2.command;
78
using Newtonsoft.Json;
@@ -121,9 +122,27 @@ public static void handleJsmod2(int id, String json,Dictionary<string,string> ma
121122

122123
if (handlers.ContainsKey(id))
123124
{
125+
JsonSetting[] response = null;
126+
127+
124128
ProxyHandler.handler.Info("handling the "+id);
125129
Handler handler = handlers[id];
126-
JsonSetting[] response = handler.handle(o,mapper);
130+
try
131+
{
132+
response = handler.handle(o,mapper);
133+
}
134+
catch (Exception e)
135+
{
136+
if (e is NullReferenceException)
137+
{
138+
var utf8WithoutBom = new UTF8Encoding(false);
139+
//捕捉空指针则返回null
140+
byte[] bytes = utf8WithoutBom.GetBytes(Convert.ToBase64String(utf8WithoutBom.GetBytes("null")));
141+
client.GetStream().Write(bytes,0,bytes.Length);
142+
return;
143+
}
144+
}
145+
127146
if (response != null)
128147
{
129148
//将response对象发出去

0 commit comments

Comments
 (0)