aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-07-27 23:03:11 +1200
committerGitHub <noreply@github.com>2017-07-27 23:03:11 +1200
commit5d6dec7818a8059c958fc896eb1de838fda52a8c (patch)
treef5759e40bbf8f9e3a4cee79b9829b27dbbef47c6
parent495b2aa2d2b17bd1a5803ea0bd7dcc64bc81c598 (diff)
parentec82098c6bc3c84672665552839a97ddb6771afc (diff)
downloadtrackermap-server-5d6dec7818a8059c958fc896eb1de838fda52a8c.tar.gz
trackermap-server-5d6dec7818a8059c958fc896eb1de838fda52a8c.tar.bz2
trackermap-server-5d6dec7818a8059c958fc896eb1de838fda52a8c.zip
Merge pull request #3397 from Abyss777/fix_empty_devices
Initialize some maps, because they might be accessed before initialized.
-rw-r--r--src/org/traccar/database/DataManager.java28
-rw-r--r--src/org/traccar/database/DeviceManager.java6
-rw-r--r--src/org/traccar/database/DriversManager.java3
-rw-r--r--src/org/traccar/database/UsersManager.java3
4 files changed, 38 insertions, 2 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 862efbc91..07ad0be44 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -37,11 +37,17 @@ import liquibase.resource.ResourceAccessor;
import org.traccar.Config;
import org.traccar.helper.Log;
+import org.traccar.model.Attribute;
import org.traccar.model.AttributeAlias;
import org.traccar.model.Device;
+import org.traccar.model.Driver;
import org.traccar.model.Event;
+import org.traccar.model.Geofence;
+import org.traccar.model.Group;
+import org.traccar.model.ManagedUser;
import org.traccar.model.Permission;
import org.traccar.model.BaseModel;
+import org.traccar.model.Calendar;
import org.traccar.model.Position;
import org.traccar.model.Server;
import org.traccar.model.Statistics;
@@ -269,8 +275,26 @@ public class DataManager {
}
public static Class<?> getClassByName(String name) throws ClassNotFoundException {
- return Class.forName("org.traccar.model."
- + name.substring(0, 1).toUpperCase() + name.replace("Id", "").substring(1));
+ switch (name.toLowerCase().replace("id", "")) {
+ case "device":
+ return Device.class;
+ case "group":
+ return Group.class;
+ case "user":
+ return User.class;
+ case "manageduser":
+ return ManagedUser.class;
+ case "geofence":
+ return Geofence.class;
+ case "driver":
+ return Driver.class;
+ case "attribute":
+ return Attribute.class;
+ case "calendar":
+ return Calendar.class;
+ default:
+ throw new ClassNotFoundException();
+ }
}
public static String makeNameId(Class<?> clazz) {
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index 4aafe6631..5d123f9b8 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -57,6 +57,12 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity
public DeviceManager(DataManager dataManager) {
super(dataManager, Device.class);
this.config = Context.getConfig();
+ if (devicesByPhone == null) {
+ devicesByPhone = new ConcurrentHashMap<>();
+ }
+ if (devicesByUniqueId == null) {
+ devicesByUniqueId = new ConcurrentHashMap<>();
+ }
dataRefreshDelay = config.getLong("database.refreshDelay", DEFAULT_REFRESH_DELAY) * 1000;
lookupGroupsAttribute = config.getBoolean("deviceManager.lookupGroupsAttribute");
fallbackToText = config.getBoolean("command.fallbackToSms");
diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java
index d3866a5f0..9defa1931 100644
--- a/src/org/traccar/database/DriversManager.java
+++ b/src/org/traccar/database/DriversManager.java
@@ -27,6 +27,9 @@ public class DriversManager extends ExtendedObjectManager<Driver> {
public DriversManager(DataManager dataManager) {
super(dataManager, Driver.class);
+ if (driversByUniqueId == null) {
+ driversByUniqueId = new ConcurrentHashMap<>();
+ }
}
private void putUniqueDriverId(Driver driver) {
diff --git a/src/org/traccar/database/UsersManager.java b/src/org/traccar/database/UsersManager.java
index 28e6a31b2..ed39f6cfa 100644
--- a/src/org/traccar/database/UsersManager.java
+++ b/src/org/traccar/database/UsersManager.java
@@ -29,6 +29,9 @@ public class UsersManager extends SimpleObjectManager<User> {
public UsersManager(DataManager dataManager) {
super(dataManager, User.class);
+ if (usersTokens == null) {
+ usersTokens = new ConcurrentHashMap<>();
+ }
}
private void putToken(User user) {