File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed
main/java/com/optimizely/ab/config/parser
test/java/com/optimizely/ab/config/parser Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,12 @@ final class GsonConfigParser implements ConfigParser {
3333
3434 @ Override
3535 public ProjectConfig parseProjectConfig (@ Nonnull String json ) throws ConfigParseException {
36+ if (json == null ) {
37+ throw new ConfigParseException ("Unable to parse null datafile." );
38+ }
39+ if (json .length () == 0 ) {
40+ throw new ConfigParseException ("Unable to parse empty datafile." );
41+ }
3642 Gson gson = new GsonBuilder ()
3743 .registerTypeAdapter (ProjectConfig .class , new ProjectConfigGsonDeserializer ())
3844 .registerTypeAdapter (Audience .class , new AudienceGsonDeserializer ())
Original file line number Diff line number Diff line change 2222import org .junit .Rule ;
2323import org .junit .Test ;
2424import org .junit .rules .ExpectedException ;
25- import static junit .framework .Assert .assertNull ;
26-
2725
2826import static com .optimizely .ab .config .ProjectConfigTestUtils .validConfigJsonV1 ;
2927import static com .optimizely .ab .config .ProjectConfigTestUtils .validProjectConfigV1 ;
@@ -92,22 +90,24 @@ public void validJsonRequiredFieldMissingExceptionWrapping() throws Exception {
9290
9391 /**
9492 * Verify that empty string JSON results in a {@link ConfigParseException} being thrown.
95- * This serializer doesn't throw exceptions on null or empty string
9693 */
9794 @ Test
9895 public void emptyJsonExceptionWrapping () throws Exception {
96+ thrown .expect (ConfigParseException .class );
97+
9998 GsonConfigParser parser = new GsonConfigParser ();
100- assertNull ( parser .parseProjectConfig ("" ) );
99+ parser .parseProjectConfig ("" );
101100 }
102101
103102 /**
104103 * Verify that null JSON results in a {@link ConfigParseException} being thrown.
105- * This serializer doesn't throw exceptions on null or empty string
106104 */
107105 @ Test
108106 @ SuppressFBWarnings (value ="NP_NONNULL_PARAM_VIOLATION" , justification ="Testing nullness contract violation" )
109107 public void nullJsonExceptionWrapping () throws Exception {
108+ thrown .expect (ConfigParseException .class );
109+
110110 GsonConfigParser parser = new GsonConfigParser ();
111- assertNull ( parser .parseProjectConfig (null ) );
111+ parser .parseProjectConfig (null );
112112 }
113113}
You can’t perform that action at this time.
0 commit comments