package org.acra.collector;

import java.util.Map;
import java.util.TreeMap;

import org.acra.ACRA;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

final class SharedPreferencesCollector {

    public static String collect(Context context) {
        final StringBuilder result = new StringBuilder();
        final Map<String, SharedPreferences> shrdPrefs = new TreeMap<String, SharedPreferences>();
        shrdPrefs.put("default", PreferenceManager.getDefaultSharedPreferences(context));
        final String[] shrdPrefsIds = ACRA.getConfig().additionalSharedPreferences();
        if (shrdPrefsIds != null) {
            for (final String shrdPrefId : shrdPrefsIds) {
                shrdPrefs.put(shrdPrefId, context.getSharedPreferences(shrdPrefId, Context.MODE_PRIVATE));
            }
        }

        for (final String prefsId : shrdPrefs.keySet()) {
            result.append(prefsId).append("\n");
            final SharedPreferences prefs = shrdPrefs.get(prefsId);
            if (prefs != null) {
                final Map<String, ?> kv = prefs.getAll();
                if (kv != null && kv.size() > 0) {
                    for (final String key : kv.keySet()) {
                        result.append(key).append("=").append(kv.get(key).toString()).append("\n");
                    }
                } else {
                    result.append("empty\n");
                }
            } else {
                result.append("null\n");
            }
            result.append("\n");
        }

        return result.toString();
    }
}

@@ -1267,32 +1267,87 @@
 kv.keySet()) %7B%0D%0A
+                        if(kv.get(key) != null) %7B%0D%0A    
                 
@@ -1423,32 +1423,171 @@
 .append(%22%5Cn%22);%0D%0A
+                        %7D else %7B%0D%0A                            result.append(key).append(%22=%22).append(%22null%5Cn%22);%0D%0A                        %7D%0D%0A
                 

Fix Issue 116 : NPE if SharedPreference value == null