mangstadt / ez-vcard

A vCard parser library for Java
Other
399 stars 92 forks source link

Getting crash when using this library #99

Closed AndroidDeveloperLB closed 4 years ago

AndroidDeveloperLB commented 4 years ago
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'

It could be because of updated dependencies, but I keep getting crashes even for the simple case of:

    StructuredName n = new StructuredName();
    n.setFamily("Doe");
    n.setGiven("Jonathan");
    n.getPrefixes().add("Mr");
    vcard.setStructuredName(n);
    vcard.setFormattedName("John Doe");
    String str = Ezvcard.write(vcard).version(VCardVersion.V4_0).go();

And of course when using VCardWriter:

        final File vcfFile = new File(path);
        vCardWriter = new VCardWriter(vcfFile, VCardVersion.V3_0);
        final VCard vCard = new VCard();
        vCard.addFormattedName(new FormattedName(displayName));
        vCardWriter.write(vCard);

The crash log:

 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.Reader.read(char[])' on a null object reference
    at java.util.Properties$LineReader.readLine(Properties.java:434)
    at java.util.Properties.load0(Properties.java:349)
    at java.util.Properties.load(Properties.java:337)
    at ezvcard.Ezvcard.<clinit>(Ezvcard.java:127)
    at ezvcard.Ezvcard.write(Ezvcard.java:470) 

Any idea how to fix it?

Tested on Pixel 2 with Android 10, but I've noticed it occurs for users too, of various types of devices and Android versions.

AndroidDeveloperLB commented 4 years ago

Seems it doesn't occur with the previous version we've used:

implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.2'

And also a newer one:

implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.4'

Only on 0.10.5

mangstadt commented 4 years ago

The static initializer of the Ezvcard class reads data from a properties file, which is located at the root of the classpath. It appears that your environment does not have this properties file for some reason.

Someone recently reported a similar issue. He said something about "proguard minify enabled" causing the problem.

AndroidDeveloperLB commented 4 years ago

It's not Proguard, because this occurs on debug mode too. Please explain how to fix this.

mangstadt commented 4 years ago

Create a package in your project named "ezvcard" and put a file called "ez-vcard.properties" in it. Populate the file with the following content:

version=0.10.5
groupId=com.googlecode.ez-vcard
artifactId=ez-vcard
url=http://github.com/mangstadt/ez-vcard
AndroidDeveloperLB commented 4 years ago

I don't understand. This seems like the dependency we already have on gradle. What is this for?

mangstadt commented 4 years ago

The groupId and artifactId properties are only used in certain situations with JSON-encoded vCards. If you leave them out, it shouldn't hurt anything else.

AndroidDeveloperLB commented 4 years ago

@mangstadt Sorry but I don't understand your solution. This is what I use:

implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.4'

And if I update it to 0.10.5, the issue appears. What do you suggest to change here?

mangstadt commented 4 years ago

Does the ez-vcard JAR file that your project uses contain a ezvcard/ez-vcard.properties file? If that file is missing, then it would cause the error you are seeing. I checked the JAR file that's hosted on Maven Central and it's not missing the file.

The only other thing I can think of is: Does the Class.getResourceAsStream method behave differently on Android than it does in Java? If it does, that might be causing the problem.

AndroidDeveloperLB commented 4 years ago

We use the repository directly via gradle. No jar file. When we use 0.10.4 version and I search for the "ez-vcard.properties" file, I find this:

image

If I update to 0.10.5, I find a similar result:

image

As for "getResourceAsStream" , what is the use case for you to use it? I think it's not recommended to use it on Android, as it has its own way to handle resources, no?


EDIT: Hmmm... That's odd. I've updated to this version and tried again running the app. And now it works... Maybe it's an issue with some of Google SDK stuff (Gradle plugin...), not building the project correctly.

Need to do further checking.

AndroidDeveloperLB commented 4 years ago

Closing this for now as I don't see the issue anymore.