Bug 509497 - Exception in VCardBuilder due to invalid/empty vcard string
Summary: Exception in VCardBuilder due to invalid/empty vcard string
Status: RESOLVED FIXED
Alias: None
Product: kdeconnect
Classification: Applications
Component: android-application (other bugs)
Version First Reported In: 25.04.2
Platform: Debian stable Linux
: NOR normal
Target Milestone: ---
Assignee: Albert Vaca Cintora
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-09-14 20:34 UTC by Scott Smith
Modified: 2025-10-04 19:16 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Scott Smith 2025-09-14 20:34:42 UTC
SUMMARY

I've been trying to determine why I see phone numbers instead of contact names. I've done all the recommended stuff (e.g. kpeople-vcard, granting phone permissions), so I looked at the KDE Connection logs from my phone and noticed an exception around creation of vcards:

Exception in ContactsPlugin's onPacketReceived()
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(String.java:2064)
	at org.kde.kdeconnect.Helpers.ContactsHelper$VCardBuilder.<init>(ContactsHelper.java:309)
	at org.kde.kdeconnect.Helpers.ContactsHelper.getVCardsSlow(ContactsHelper.java:158)
	at org.kde.kdeconnect.Helpers.ContactsHelper.getVCardsForContactIDs(ContactsHelper.java:176)
	at org.kde.kdeconnect.Plugins.ContactsPlugin.ContactsPlugin.handleRequestVCardsByUIDs(ContactsPlugin.java:216)
	at org.kde.kdeconnect.Plugins.ContactsPlugin.ContactsPlugin.onPacketReceived(ContactsPlugin.java:255)
	at org.kde.kdeconnect.Device.notifyPluginPacketReceived(Device.kt:433)
	at org.kde.kdeconnect.Device.onPacketReceived(Device.kt:422)
	at org.kde.kdeconnect.Backends.BaseLink.packetReceived(BaseLink.java:60)
	at org.kde.kdeconnect.Backends.LanBackend.LanLink.receivedNetworkPacket(LanLink.java:256)
	at org.kde.kdeconnect.Backends.LanBackend.LanLink.$r8$lambda$1roQrklD197DaNpVzAP29DenyWc(LanLink.java:90)
	at org.kde.kdeconnect.Backends.LanBackend.LanLink$$ExternalSyntheticLambda1.run(R8$$SyntheticClass:0)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
	at java.lang.Thread.run(Thread.java:920)

I didn't bring it up in a debugger, so I'm not sure whether the vcard string passed into the constructor was empty (my guess), or simply didn't contain an "END:VCARD":

        VCardBuilder(String vcard) {
            // Remove the end tag. We will add it back on in .toString()
            vcard = vcard.substring(0, vcard.indexOf(VCARD_END));

            vcardBody = new StringBuilder(vcard);
        }

NOTE: The try/catch is located INSIDE the loop, suggesting that some outlier among my contacts would only affect that contact and not the entire list. Thus I suspect that there is some earlier issue preventing the contact information from reaching this point...

STEPS TO REPRODUCE

    1. After connecting my Galaxy Note 10+ phone (LAN/Wi-Fi), I open KDE Connect SMS. I see a list of conversations, but phone numbers and the generic contact icon are displayed for each rather than contact information and avatar images.

OBSERVED RESULT

    Conversations appear in a list, but phone numbers are displayed instead of contact information.

EXPECTED RESULT

    Contact avatar images and names should be displayed for each item in the list.

SOFTWARE/OS VERSIONS
    Linux/KDE Plasma: Debian GNU/Linux 14 (Trixie)
    KDE Plasma Version: 6.3.6
    KDE Frameworks Version: 6.13.0
    Qt Version: 6.8.2

ADDITIONAL INFORMATION
Comment 1 Albert Vaca Cintora 2025-10-04 19:16:34 UTC
Git commit 647dd6ca27c1f7dbea902ad7286a89955d3a1b24 by Albert Vaca Cintora.
Committed on 04/10/2025 at 17:59.
Pushed by albertvaka into branch 'master'.

ContactsHelper: Catch any exception parsing VCards

If a card can't be parsed, we should not fail the whole batch.

M  +1    -1    src/org/kde/kdeconnect/Helpers/ContactsHelper.java

https://invent.kde.org/network/kdeconnect-android/-/commit/647dd6ca27c1f7dbea902ad7286a89955d3a1b24