koraktor / steam-condenser

A multi-language library for querying the Steam Community, Source, GoldSrc servers and Steam master servers
https://koraktor.de/steam-condenser
Other
356 stars 67 forks source link

Java - Unable to parse XML (Unparsable date) #273

Closed shaunidiot closed 7 years ago

shaunidiot commented 9 years ago

I have 2 Android applications using Steam Condenser for Java. Recently, both of them have failed to work due to the same problem. Unparsable date.

An example of the error log.

com.github.koraktor.steamcondenser.exceptions.SteamCondenserException: XML data could not be parsed.
at com.github.koraktor.steamcondenser.steam.community.SteamId.fetchData(SteamId.java:394)
at com.github.koraktor.steamcondenser.steam.community.SteamId.<init>(SteamId.java:299)
at com.github.koraktor.steamcondenser.steam.community.SteamId.create(SteamId.java:237)
at com.github.koraktor.steamcondenser.steam.community.SteamId.create(SteamId.java:143)
at com.test.removed.$getSteamId.doInBackground(CSGOPreference.java:128)
at com.test.removed$getSteamId.doInBackground(CSGOPreference.java:110)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.text.ParseException: Unparseable date: "November 14null, 2011, 2015" (at offset 11)
at java.text.DateFormat.parse(DateFormat.java:555)
at com.github.koraktor.steamcondenser.steam.community.SteamId.fetchData(SteamId.java:367)
... 11 more

The code I'm using:

SteamId id = SteamId.create("whatevernamehere");
SteamID = Long.toString(id.getSteamId64());

Any idea on how to solve it? Thank you!

koraktor commented 9 years ago

Looks like the XML data is broken for those profiles. Do you have examples or does it fail for all profiles?

Dates have always been problematic in the XML data because of various format changes and inconsistencies.

shaunidiot commented 9 years ago

I did a quick test on an Android app.

new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... voids) {

                    ArrayList<String> names = new ArrayList<String>();
                    // add 6 usernames here. 5 were public profiles. 1 was private.
                    for (String name : names) {
                        try {
                            SteamId id = SteamId.create(name);
                            Log.e("Id64", Long.toString(id.getSteamId64()));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                return null;
            }
        }.execute();

Results : Only the first and the last returned the SteamId64. The rest returned the same error.

com.github.koraktor.steamcondenser.exceptions.SteamCondenserException: XML data could not be parsed.
Caused by: java.text.ParseException: Unparseable date: "November 18null, 2012, 2015" (at offset 11)

Took a look in the profile xml files for memberSince tag. First: December 21st, 2010 Second: May 14th, 2006 Third: June 4th, 2011 Fourth: November 18th, 2012 FIfth: September 10th, 2011 Sixth: Private profile. So the Steam64Id was returned.

The date for all of them is similar, so the one causing the crash on the second to fifth profile was pretty weird. The code seems to be unable to parse the date and causing it to run

this.memberSince = DATE_FORMAT.parse(memberSince + ", " + Calendar.getInstance().get(Calendar.YEAR));

Thanks a lot, and sorry for any English sentence error.

koraktor commented 9 years ago

Do you have any profile IDs or custom URLs that I can check?

shaunidiot commented 9 years ago

Will remove when you've replied me. The above result is used in this order.

removed
koraktor commented 9 years ago

Ok, I'll have a look.

koraktor commented 9 years ago

Sorry, I'm unable to reproduce this problem. All of the provided example profiles work for me.

Can you give some information about your environment? Java version and locale in particular.

shaunidiot commented 9 years ago

I got a feeling it's due to the Java environment I'm working on/targeted for the Android project. I'm using JDK v 1.8.0_31.

liammcnabb commented 9 years ago

I am having the same problem. com.github.koraktor.steamcondenser.exceptions.SteamCondenserException: XML data could not be parsed: null at com.github.koraktor.steamcondenser.steam.community.XMLData.<init>(XMLData.java:70) com.github.koraktor.steamcondenser.steam.community.SteamId.fetchData(SteamId.java:330) com.github.koraktor.steamcondenser.steam.community.SteamId.<init>(SteamId.java:299) com.github.koraktor.steamcondenser.steam.community.SteamId.create(SteamId.java:237) com.github.koraktor.steamcondenser.steam.community.SteamId.create(SteamId.java:175)

It happens when you allow the library to fetch the id's data on creation, and seems to be happening regardless of what I put in.

I am also using this with an android application

koraktor commented 9 years ago

Can you provide example profiles?

liammcnabb commented 9 years ago

I haven't been able to get it to work, so I have been using the profile "demomenz" which I found on the usage section of the website

koraktor commented 9 years ago

@liammcnabb What Java and Steam Condenser version are you using?

This code works flawlessly for me:

SteamId id = SteamId.create("demomenz", true);

The exception you posted hints at some JRE internal problem when parsing the XML. Can you also post the root exception that caused the SteamCondenserException (see #getCause).

koraktor commented 7 years ago

I guess there’s no way to reproduce this now.