|
1 | 1 | /**************************************************************************** |
2 | | - * Copyright 2016-2017, Optimizely, Inc. and contributors * |
| 2 | + * Copyright 2016-2018, Optimizely, Inc. and contributors * |
3 | 3 | * * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); * |
5 | 5 | * you may not use this file except in compliance with the License. * |
|
43 | 43 | import com.optimizely.ab.notification.NotificationBroadcaster; |
44 | 44 | import com.optimizely.ab.notification.NotificationCenter; |
45 | 45 | import com.optimizely.ab.notification.NotificationListener; |
46 | | - |
47 | 46 | import org.slf4j.Logger; |
48 | 47 | import org.slf4j.LoggerFactory; |
49 | 48 |
|
| 49 | +import javax.annotation.CheckForNull; |
| 50 | +import javax.annotation.Nonnull; |
| 51 | +import javax.annotation.Nullable; |
| 52 | +import javax.annotation.concurrent.ThreadSafe; |
50 | 53 | import java.util.ArrayList; |
51 | 54 | import java.util.Collections; |
52 | 55 | import java.util.HashMap; |
53 | 56 | import java.util.List; |
54 | 57 | import java.util.Map; |
55 | 58 |
|
56 | | -import javax.annotation.CheckForNull; |
57 | | -import javax.annotation.Nonnull; |
58 | | -import javax.annotation.Nullable; |
59 | | -import javax.annotation.concurrent.ThreadSafe; |
60 | | - |
61 | 59 | /** |
62 | 60 | * Top-level container class for Optimizely functionality. |
63 | 61 | * Thread-safe, so can be created as a singleton and safely passed around. |
@@ -333,6 +331,14 @@ public void track(@Nonnull String eventName, |
333 | 331 | public @Nonnull Boolean isFeatureEnabled(@Nonnull String featureKey, |
334 | 332 | @Nonnull String userId, |
335 | 333 | @Nonnull Map<String, String> attributes) { |
| 334 | + if (featureKey == null) { |
| 335 | + logger.warn("The featureKey parameter must be nonnull."); |
| 336 | + return false; |
| 337 | + } |
| 338 | + else if (userId == null) { |
| 339 | + logger.warn("The userId parameter must be nonnull."); |
| 340 | + return false; |
| 341 | + } |
336 | 342 | FeatureFlag featureFlag = projectConfig.getFeatureKeyMapping().get(featureKey); |
337 | 343 | if (featureFlag == null) { |
338 | 344 | logger.info("No feature flag was found for key \"{}\".", featureKey); |
@@ -533,6 +539,18 @@ String getFeatureVariableValueForType(@Nonnull String featureKey, |
533 | 539 | @Nonnull String userId, |
534 | 540 | @Nonnull Map<String, String> attributes, |
535 | 541 | @Nonnull LiveVariable.VariableType variableType) { |
| 542 | + if (featureKey == null) { |
| 543 | + logger.warn("The featureKey parameter must be nonnull."); |
| 544 | + return null; |
| 545 | + } |
| 546 | + else if (variableKey == null) { |
| 547 | + logger.warn("The variableKey parameter must be nonnull."); |
| 548 | + return null; |
| 549 | + } |
| 550 | + else if (userId == null) { |
| 551 | + logger.warn("The userId parameter must be nonnull."); |
| 552 | + return null; |
| 553 | + } |
536 | 554 | FeatureFlag featureFlag = projectConfig.getFeatureKeyMapping().get(featureKey); |
537 | 555 | if (featureFlag == null) { |
538 | 556 | logger.info("No feature flag was found for key \"{}\".", featureKey); |
|
0 commit comments