mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-02 11:05:28 -04:00
Merge pull request #846 from stleary/cleanup-and-merge-tests
Cleanup warnings and merge new unit tests
This commit is contained in:
commit
55b824d4c4
3
pom.xml
3
pom.xml
@ -104,6 +104,9 @@
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<compilerArgs>
|
||||
<arg>-Xlint:unchecked</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -1359,7 +1359,8 @@ public class JSONArray implements Iterable<Object> {
|
||||
* The subscript.
|
||||
* @param value
|
||||
* The Map value.
|
||||
* @return this.
|
||||
* @return
|
||||
* reference to self
|
||||
* @throws JSONException
|
||||
* If the index is negative or if the value is an invalid
|
||||
* number.
|
||||
@ -1381,7 +1382,7 @@ public class JSONArray implements Iterable<Object> {
|
||||
* The Map value.
|
||||
* @param jsonParserConfiguration
|
||||
* Configuration object for the JSON parser
|
||||
* @return
|
||||
* @return reference to self
|
||||
* @throws JSONException
|
||||
* If the index is negative or if the value is an invalid
|
||||
* number.
|
||||
|
@ -55,11 +55,13 @@ public class JSONMLParserConfiguration extends ParserConfiguration {
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public JSONMLParserConfiguration withKeepStrings(final boolean newVal) {
|
||||
return super.withKeepStrings(newVal);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public JSONMLParserConfiguration withMaxNestingDepth(int maxNestingDepth) {
|
||||
return super.withMaxNestingDepth(maxNestingDepth);
|
||||
|
@ -17,6 +17,7 @@ public class JSONParserConfiguration extends ParserConfiguration {
|
||||
return new JSONParserConfiguration();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public JSONParserConfiguration withMaxNestingDepth(final int maxNestingDepth) {
|
||||
return super.withMaxNestingDepth(maxNestingDepth);
|
||||
|
@ -75,6 +75,7 @@ public class ParserConfiguration {
|
||||
*
|
||||
* @return The existing configuration will not be modified. A new configuration is returned.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ParserConfiguration> T withKeepStrings(final boolean newVal) {
|
||||
T newConfig = (T)this.clone();
|
||||
newConfig.keepStrings = newVal;
|
||||
@ -101,6 +102,7 @@ public class ParserConfiguration {
|
||||
*
|
||||
* @return The existing configuration will not be modified. A new configuration is returned.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ParserConfiguration> T withMaxNestingDepth(int maxNestingDepth) {
|
||||
T newConfig = (T)this.clone();
|
||||
|
||||
|
@ -192,6 +192,7 @@ public class XMLParserConfiguration extends ParserConfiguration {
|
||||
*
|
||||
* @return The existing configuration will not be modified. A new configuration is returned.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public XMLParserConfiguration withKeepStrings(final boolean newVal) {
|
||||
return super.withKeepStrings(newVal);
|
||||
@ -309,6 +310,7 @@ public class XMLParserConfiguration extends ParserConfiguration {
|
||||
* @param maxNestingDepth the maximum nesting depth allowed to the XML parser
|
||||
* @return The existing configuration will not be modified. A new configuration is returned.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public XMLParserConfiguration withMaxNestingDepth(int maxNestingDepth) {
|
||||
return super.withMaxNestingDepth(maxNestingDepth);
|
||||
@ -316,7 +318,7 @@ public class XMLParserConfiguration extends ParserConfiguration {
|
||||
|
||||
/**
|
||||
* To enable explicit end tag with empty value.
|
||||
* @param closeEmptyTag
|
||||
* @param closeEmptyTag new value for the closeEmptyTag property
|
||||
* @return same instance of configuration with empty tag config updated
|
||||
*/
|
||||
public XMLParserConfiguration withCloseEmptyTag(boolean closeEmptyTag){
|
||||
|
@ -3760,6 +3760,48 @@ public class JSONObjectTest {
|
||||
String jsonString = object.toString();
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
public void testCircleReferenceFirstLevel() {
|
||||
Map<Object, Object> jsonObject = new HashMap<>();
|
||||
|
||||
jsonObject.put("test", jsonObject);
|
||||
|
||||
new JSONObject(jsonObject, new JSONParserConfiguration());
|
||||
}
|
||||
|
||||
@Test(expected = StackOverflowError.class)
|
||||
public void testCircleReferenceMultiplyLevel_notConfigured_expectedStackOverflow() {
|
||||
Map<Object, Object> inside = new HashMap<>();
|
||||
|
||||
Map<Object, Object> jsonObject = new HashMap<>();
|
||||
inside.put("test", jsonObject);
|
||||
jsonObject.put("test", inside);
|
||||
|
||||
new JSONObject(jsonObject, new JSONParserConfiguration().withMaxNestingDepth(99999));
|
||||
}
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
public void testCircleReferenceMultiplyLevel_configured_expectedJSONException() {
|
||||
Map<Object, Object> inside = new HashMap<>();
|
||||
|
||||
Map<Object, Object> jsonObject = new HashMap<>();
|
||||
inside.put("test", jsonObject);
|
||||
jsonObject.put("test", inside);
|
||||
|
||||
new JSONObject(jsonObject, new JSONParserConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDifferentKeySameInstanceNotACircleReference() {
|
||||
Map<Object, Object> map1 = new HashMap<>();
|
||||
Map<Object, Object> map2 = new HashMap<>();
|
||||
|
||||
map1.put("test1", map2);
|
||||
map1.put("test2", map2);
|
||||
|
||||
new JSONObject(map1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to build nested map of max maxDepth
|
||||
*
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
*/
|
||||
public class WeirdList {
|
||||
/** */
|
||||
private final List<Integer> list = new ArrayList();
|
||||
private final List<Integer> list = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* @param vals
|
||||
@ -25,14 +25,14 @@ public class WeirdList {
|
||||
* @return a copy of the list
|
||||
*/
|
||||
public List<Integer> get() {
|
||||
return new ArrayList(this.list);
|
||||
return new ArrayList<>(this.list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a copy of the list
|
||||
*/
|
||||
public List<Integer> getALL() {
|
||||
return new ArrayList(this.list);
|
||||
return new ArrayList<>(this.list);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user