Skip to content

Commit 253b6d8

Browse files
author
yhl
committed
fix eventName bug & appid check
1 parent a6a5ed3 commit 253b6d8

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

AnalysysJavasdk/src/main/java/cn/com/analysys/javasdk/AnalysysJavaSdk.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public AnalysysJavaSdk(Collecter collecter, String appId){
3535
*/
3636
public AnalysysJavaSdk(Collecter collecter, String appId, Boolean autoDelParam){
3737
this.collecter = collecter;
38+
if(appId == null || appId.trim().length() == 0){
39+
throw new RuntimeException("appKey is empty");
40+
}
3841
this.appId = appId;
3942
this.egBaseProperties = new HashMap<String, Object>(3);
4043
this.xcontextSuperProperties = new ConcurrentHashMap<String, Object>();
@@ -302,7 +305,7 @@ private void upload(String distinctId, boolean isLogin, String eventName, Map<St
302305
eventMap.put("appid", appId);
303306
Map<String, Object> newProperties = new HashMap<String, Object>(16);
304307
String profile = "$profile";
305-
if(!eventName.startsWith(profile) && !eventName.startsWith(EventName.ALIAS.getValue())){
308+
if(!(eventName != null && (eventName.startsWith(profile) || eventName.startsWith(EventName.ALIAS.getValue())))){
306309
newProperties.putAll(this.xcontextSuperProperties);
307310
}
308311
newProperties.put("$debug", debugMode);
@@ -318,8 +321,8 @@ private void upload(String distinctId, boolean isLogin, String eventName, Map<St
318321
eventMap.put("xcontext", newProperties);
319322
this.collecter.debug(isDebug());
320323
boolean ret = this.collecter.send(eventMap);
321-
if(eventName.startsWith(profile) && isDebug() && ret){
322-
System.out.println(String.format("%s success.", eventName.substring(1)));
324+
if(eventName != null && eventName.startsWith(profile) && isDebug() && ret){
325+
System.out.println(String.format("%s success.", eventName));
323326
}
324327
}
325328

AnalysysJavasdk/src/main/java/cn/com/analysys/javasdk/ValidHandle.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,19 @@ public static void checkProperty(String distinctId, String eventName, Map<String
163163
throw new AnalysysException(String.format("original_id %s is too long, max length is %s.", properties.get(originalId), idLength));
164164
}
165165
}
166-
167-
if (eventName == null || eventName.length() == 0) {
168-
System.out.println(String.format("EventName %s is empty.", eventName));
166+
if (eventName != null) {
167+
if (eventName.length() == 0) {
168+
System.out.println("EventName is empty.");
169169
}
170170
if (eventName.length() > eventNameLen) {
171171
System.out.println(String.format("EventName %s is too long, max length is %s.", eventName, eventNameLen));
172172
}
173173
if (!(KEY_PATTERN.matcher(eventName).matches())) {
174174
System.out.println(String.format("EventName %s is invalid.", eventName));
175175
}
176+
} else {
177+
System.out.println("EventName is null.");
178+
}
176179
checkParam(eventName, properties);
177180
}
178181

0 commit comments

Comments
 (0)