@Test public void testSanitize() throws Exception { Properties props = new Properties(); props.put(new int[4], new HashMap(2)); props.put("A", new File("B")); props.put("4", new HashMap(2)); props.put("1, two, 3.0", new char[5]); props.put("list", ImmutableList.of(1, 2)); Properties sanitized = Instructions.sanitize(props); assertThat(sanitized) .containsEntry("A", "B") .containsEntry("4", "{}") .containsEntry("1, two, 3.0", "\u0000, \u0000, \u0000, \u0000, \u0000") .containsEntry("0, 0, 0, 0", "{}") .containsEntry("list", "1, 2"); }
public static Properties sanitize(Properties properties) { Properties sanitizedEntries = new Properties(); for (Iterator<?> itr = properties.entrySet().iterator(); itr.hasNext(); ) { Map.Entry entry = (Map.Entry) itr.next(); if (!(entry.getKey() instanceof String)) { String key = sanitize(entry.getKey()); if (!properties.containsKey(key)) { sanitizedEntries.setProperty(key, sanitize(entry.getValue())); } itr.remove(); } else if (!(entry.getValue() instanceof String)) { entry.setValue(sanitize(entry.getValue())); } } properties.putAll(sanitizedEntries); return properties; }
Instructions { public static Properties sanitize(Properties properties) { Properties sanitizedEntries = new Properties(); for (Iterator<?> itr = properties.entrySet().iterator(); itr.hasNext(); ) { Map.Entry entry = (Map.Entry) itr.next(); if (!(entry.getKey() instanceof String)) { String key = sanitize(entry.getKey()); if (!properties.containsKey(key)) { sanitizedEntries.setProperty(key, sanitize(entry.getValue())); } itr.remove(); } else if (!(entry.getValue() instanceof String)) { entry.setValue(sanitize(entry.getValue())); } } properties.putAll(sanitizedEntries); return properties; } }
Instructions { public static Properties sanitize(Properties properties) { Properties sanitizedEntries = new Properties(); for (Iterator<?> itr = properties.entrySet().iterator(); itr.hasNext(); ) { Map.Entry entry = (Map.Entry) itr.next(); if (!(entry.getKey() instanceof String)) { String key = sanitize(entry.getKey()); if (!properties.containsKey(key)) { sanitizedEntries.setProperty(key, sanitize(entry.getValue())); } itr.remove(); } else if (!(entry.getValue() instanceof String)) { entry.setValue(sanitize(entry.getValue())); } } properties.putAll(sanitizedEntries); return properties; } private  Instructions(); }
Instructions { public static Properties sanitize(Properties properties) { Properties sanitizedEntries = new Properties(); for (Iterator<?> itr = properties.entrySet().iterator(); itr.hasNext(); ) { Map.Entry entry = (Map.Entry) itr.next(); if (!(entry.getKey() instanceof String)) { String key = sanitize(entry.getKey()); if (!properties.containsKey(key)) { sanitizedEntries.setProperty(key, sanitize(entry.getValue())); } itr.remove(); } else if (!(entry.getValue() instanceof String)) { entry.setValue(sanitize(entry.getValue())); } } properties.putAll(sanitizedEntries); return properties; } private  Instructions(); static Properties merge(Properties properties, File extra); static Properties mergeAndOverrideExisting(Properties props1, Properties props2); static Properties mergeAndSkipExisting(Properties props1, Properties props2); static Properties load(File file); static Properties sanitize(Properties properties); }
Instructions { public static Properties sanitize(Properties properties) { Properties sanitizedEntries = new Properties(); for (Iterator<?> itr = properties.entrySet().iterator(); itr.hasNext(); ) { Map.Entry entry = (Map.Entry) itr.next(); if (!(entry.getKey() instanceof String)) { String key = sanitize(entry.getKey()); if (!properties.containsKey(key)) { sanitizedEntries.setProperty(key, sanitize(entry.getValue())); } itr.remove(); } else if (!(entry.getValue() instanceof String)) { entry.setValue(sanitize(entry.getValue())); } } properties.putAll(sanitizedEntries); return properties; } private  Instructions(); static Properties merge(Properties properties, File extra); static Properties mergeAndOverrideExisting(Properties props1, Properties props2); static Properties mergeAndSkipExisting(Properties props1, Properties props2); static Properties load(File file); static Properties sanitize(Properties properties);  }