testmycode / tmc-intellij

*BETA* TestMyCode plugin for IntelliJ IDEA
MIT License
24 stars 13 forks source link

java.lang.ArrayIndexOutOfBoundsException: -1 #131

Closed pihvi closed 6 years ago

pihvi commented 6 years ago

I had a TMC exercise open in Idea when I opened another non TMC project in new window, where I got this error:

-1 java.lang.ArrayIndexOutOfBoundsException: -1 at fi.helsinki.cs.tmc.intellij.services.ObjectFinder.findCurrentProject(ObjectFinder.java:174) at fi.helsinki.cs.tmc.intellij.io.ProjectOpener.openProject(ProjectOpener.java:36) at fi.helsinki.cs.tmc.intellij.io.ProjectOpener.openProject(ProjectOpener.java:76) at fi.helsinki.cs.tmc.intellij.services.exercises.NextExerciseFetcher.openFirst(NextExerciseFetcher.java:90) at fi.helsinki.cs.tmc.intellij.services.exercises.ExerciseDownloadingService$2.lambda$run$0(ExerciseDownloadingService.java:133) at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:314) at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.a(LaterInvocator.java:416) at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:399) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762) at java.awt.EventQueue.access$500(EventQueue.java:98) at java.awt.EventQueue$3.run(EventQueue.java:715) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.awt.EventQueue.dispatchEvent(EventQueue.java:732) at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:821) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:649) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:365) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

pirtnea commented 6 years ago

I tried to replicate this on my computer and I'm not getting any errors after opening or running the non-TMC project. Did this appear right after opening the non-TMC project window or did you do something else to trigger the problem?

pihvi commented 6 years ago

I don't think I did anything else. But looking at where the error comes from, maybe you can think of a case where returned projects array is empty, then this error will happen here:

https://github.com/testmycode/tmc-intellij/blob/master/tmc-plugin-intellij/src/main/java/fi/helsinki/cs/tmc/intellij/services/ObjectFinder.java#L174

That is, there is a possibility for that index out of bounds case, when the returned project array is an empty array and maybe it should be checked in any case.. I don't know why was that code executed when I opened another non TMC project while one TMC project was open or why did it return an empty array in that case. But an easy fix for now would be to check if the array is non empty before trying to return its last value.