Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.ArrayIndexOutOfBoundsException error when calling accessibility #395

Open
phily5051 opened this issue Jul 17, 2024 · 6 comments
Open

Comments

@phily5051
Copy link

I am trying to calculate accessibility for for a medium size number of points in Montreal using walk and transit but ran into the following error: java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException
1106 out of 2522 origins processed.
2455 out of 2522 origins processed.

Before I updated the Java SE Development Kit 11 to 21, it calculated accessibility for both modes, but now it is not working. I've included a subset of points and the files that should reproduce the error.

Data files:

# assign more RAM to java
options(java.parameters = "-Xmx12G")

# essential packages
library(r5r)
library(accessibility)
library(sf)
library(data.table)
library(ggplot2)
library(interp)
library(h3jsr)
library(dplyr)

# build network dataset
r5r_core <- setup_r5(data_path = 'data/Montreal/')

# setting up the modes for general transit access
mode <- c("WALK", "TRANSIT") 
max_walk_time <- 30 
travel_time_cutoff <- 30  
departure_datetime <- as.POSIXct("12-04-2023 08:00:00", format = "%d-%m-%Y %H:%M:%S") 
time_window <- 30 
percentiles <- 50

# data points
orgpoints <- fread(file.path("data/Montreal/PopGrid1km.csv"))
destpoints <- fread(file.path("data/Montreal/POI.csv"))

# accessibility
access <- accessibility(r5r_core,
                        origins = orgpoints,
                        destinations = destpoints,
                        mode = mode,
                        opportunities_colnames = c("supermarket"),
                        decay_function = "step",
                        cutoffs = travel_time_cutoff,
                        departure_datetime = departure_datetime,
                        max_walk_time = max_walk_time,
                        time_window = time_window,
                        percentiles = percentiles,
                        progress = TRUE)

The output and the error messages are as follows:

Warning in assign_points_input(origins, "origins") :
  'origins$id' forcefully cast to character.
Warning in assign_points_input(destinations, "destinations") :
  'destinations$id' forcefully cast to character.
621 out of 2522 origins processed.Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl,  : 
  java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException
624 out of 2522 origins processed.
2455 out of 2522 origins processed.

No error occurs when I use mode <- "WALK". Any opinion will be much appreciated.

@rafapereirabr
Copy link
Member

Could you please run r5r::r5r_sitrep() and share the output below ?

@phily5051
Copy link
Author

Hello, @rafapereirabr.
I ran r5r::r5r_sitrep() and the below is the output:

$r5r_package_version
[1] ‘2.0’

$r5_jar_version
[1] "7.1"

$java_version
[1] "21.0.4"

$set_memory
[1] "-Xmx12G"

$session_info
R version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=Korean_Korea.utf8  LC_CTYPE=Korean_Korea.utf8   
[3] LC_MONETARY=Korean_Korea.utf8 LC_NUMERIC=C                 
[5] LC_TIME=Korean_Korea.utf8    

time zone: Europe/London
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] dplyr_1.1.4         h3jsr_1.3.1         interp_1.1-6       
[4] ggplot2_3.5.1       data.table_1.15.4   sf_1.0-16          
[7] accessibility_1.4.0 r5r_2.0             rJava_1.0-11       

loaded via a namespace (and not attached):
 [1] utf8_1.2.4         generics_0.1.3     tidyr_1.3.1       
 [4] class_7.3-22       KernSmooth_2.23-24 digest_0.6.36     
 [7] magrittr_2.0.3     evaluate_0.24.0    grid_4.4.1        
[10] fastmap_1.2.0      jsonlite_1.8.8     backports_1.5.0   
[13] e1071_1.7-14       DBI_1.2.3          purrr_1.0.2       
[16] fansi_1.0.6        scales_1.3.0       Rdpack_2.6        
[19] cli_3.6.3          rlang_1.1.4        units_0.8-5       
[22] rbibutils_2.2.16   bit64_4.0.5        munsell_0.5.1     
[25] withr_3.0.0        yaml_2.3.9         tools_4.4.1       
[28] deldir_2.0-4       checkmate_2.3.1    colorspace_2.1-0  
[31] geojsonsf_2.0.3    curl_5.2.1         vctrs_0.6.5       
[34] R6_2.5.1           proxy_0.4-27       lifecycle_1.0.4   
[37] classInt_0.4-10    bit_4.0.5          V8_4.4.2          
[40] pkgconfig_2.0.3    pillar_1.9.0       gtable_0.3.5      
[43] glue_1.7.0         Rcpp_1.0.12        xfun_0.45         
[46] tibble_3.2.1       tidyselect_1.2.1   rstudioapi_0.16.0 
[49] knitr_1.48         htmltools_0.5.8.1  rmarkdown_2.27    
[52] compiler_4.4.1    

@rafapereirabr
Copy link
Member

Thanks, @phily5051 . I was able to reproduce the error. It only occurs when using "TRANSIT" as a transportation mode. The code works fine for walking trips, for example.

This leads me to think the error is not in r5r but in the GTFS data. I would strongly suggest you check for any issues in the transit data using the GTFS validator available in the {gtfstools} package..

Once the issue in the GTFS is fixed, you will need to build the network again setting overwrite = TRUE.

r5r_core <- setup_r5(data_path = 'data/Montreal/', overwrite = TRUE)

@mattwigway
Copy link
Contributor

@rafapereirabr is there a way to get rJava to print a full traceback for these Java exceptions? That would make debugging a lot easier.

@rafapereirabr
Copy link
Member

@mattwigway , yes it is possible to traceback Java exceptions with {rJava}. See this SO a Q&A. We use this in the setup_r5() function already (see here). I've looked into the accessibility() and travel_time_matrix() functions but I didn't find a way to implement this there.

@mattwigway
Copy link
Contributor

If we can't do it on the r side we should be able to catch it on the Java side, print the traceback, and then re-throw so that R knows it failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants