Campus-Android icon indicating copy to clipboard operation
Campus-Android copied to clipboard

Ticket view crashing when clicking "View Ticket" after reset of TUMonline token

Open AndreasChris opened this issue 6 years ago • 0 comments

In the process of testing the changes I made to the event section of the app, I purchased several tickets (for Mario and Drachenzähmen leicht gemacht) in order to check all corner cases. Inititally displaying the purchased tickets worked perfectly fine.

After everything was done, I deleted the app from my phone as well as the associated TUMonline token in my TUMonline account, reinstalled the app and reconnected it to TUMonline. Since then, a click on the "View Ticket" Button results in the App crashing (for both events I have purchased tickets for).

Steps to Reproduce

  1. Install the App and connect it to TUMonline
  2. Purchase a ticket for any event
  3. Uninstall the app 3.5. Delete old TUMonline token from your Account (might not be necessary)
  4. Reinstall the App
  5. Reconnect it to TUMonline with a newly generated token
  6. Navigate to the event you purchased tickets for and click on "View Ticket"

Expected Result

Ticket including QR-Code should be shown.

Actual Result

The App crashes.

  E/AndroidRuntime: FATAL EXCEPTION: main
    Process: de.tum.in.tumcampus, PID: 25393
    java.lang.RuntimeException: Unable to start activity ComponentInfo{de.tum.in.tumcampus/de.tum.in.tumcampusapp.component.ui.ticket.activity.ShowTicketActivity}: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
     Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.get(ArrayList.java:437)
        at de.tum.in.tumcampusapp.component.ui.ticket.activity.ShowTicketActivity.showQRCode(ShowTicketActivity.java:94)
        at de.tum.in.tumcampusapp.component.ui.ticket.activity.ShowTicketActivity.onCreate(ShowTicketActivity.java:89)
        at android.app.Activity.performCreate(Activity.java:6975)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6541) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

Problem

public class ShowTicketActivity extends BaseActivity :
  public void onCreate(Bundle savedInstanceState)
    private void loadTicketData(int eventId)
      ticketInfoList = ticketsLocalRepo.getTicketsByEventId(eventId);
        fun getTicketsByEventId(eventId: Int): List<TicketInfo> = database.ticketDao().getByEventId(eventId)
          public TicketDao ticketDao()
          public List<TicketInfo> getByEventId(final int eventId)
            "SELECT count(*) as count, t.*, tt.* FROM tickets t, ticket_types tt WHERE t.event_id = ? AND 
             t.ticket_type_id = tt.id GROUP BY t.ticket_type_id" 
                 // => empty table => skip both while loops, since there is nothing to loop through
            final List<TicketInfo> _result = new ArrayList<TicketInfo>(_cursor.getCount()); 
                // => an Array list of size null => return empty Array List

    private void setViewData()
    private void showQRCode()
      String qrCodeContent = ticketInfoList.get(0).getTickets().get(0).getCode();
          // => try to access first element of empty array, which leads to the app crashing

So basically as far as I can tell what happens is, that the sql query in getByEventId(eventId) returns an empty table, which leads to an emty ArrayList (instead of ticket data) being returned. Since the method showQRCode() tries to access the Array List during QR-Code creation, an exception is thrown and the app crashes.

I have a feeling that this might be a Server Side issue and there's only so much I can do about that. Interestingly the app is still able to obtain the information THAT a ticket has been purchased.

Are purchased tickets somehow associated with the specific TUMonline token used during their creation (please don't do that...)?

Environment

I have reproduced this both with the version containing my changes as well as the current play store version on a Xiaomi MI 8 running lineageos 16 as well as the Emulator in Android Studio (Pixel API 26, Android 8.0.0).

AndreasChris avatar Apr 19 '19 18:04 AndreasChris