Error in .jcheck: Java Exception <no description because toString() failed

I have a shiny app that works fine in my laptop. However, when I deploy it to shinyapp.io, I get the error message in the title above. It uses RJDBC to connect to a database to get data. I am confused why it works locally but not in shinyapps.io. Below is the session info for my local R installation. Further, rJava::.jinit() returns 0.

sessionInfo()
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

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

other attached packages:
[1] rsconnect_0.8.29 DT_0.26 plotly_4.10.1
[4] ggplot2_3.4.0 gridExtra_2.3 RJDBC_0.2-10
[7] rJava_1.0-6 DBI_1.1.3 openxlsx_4.2.5.1
[10] purrr_1.0.0 lubridate_1.9.0 timechange_0.1.1
[13] tidyr_1.2.1 dplyr_1.0.10 shiny_1.7.4

loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 assertthat_0.2.1 digest_0.6.31
[4] packrat_0.9.0 utf8_1.2.2 mime_0.12
[7] R6_2.5.1 httr_1.4.4 pillar_1.8.1
[10] rlang_1.0.6 lazyeval_0.2.2 curl_4.3.3
[13] fontawesome_0.4.0 rstudioapi_0.14 data.table_1.14.6
[16] jquerylib_0.1.4 htmlwidgets_1.6.0 munsell_0.5.0
[19] compiler_4.2.2 httpuv_1.6.7 pkgconfig_2.0.3
[22] askpass_1.1 htmltools_0.5.4 openssl_2.0.5
[25] tidyselect_1.2.0 tibble_3.1.8 fansi_1.0.3
[28] viridisLite_0.4.1 withr_2.5.0 later_1.3.0
[31] grid_4.2.2 jsonlite_1.8.4 xtable_1.8-4
[34] gtable_0.3.1 lifecycle_1.0.3 magrittr_2.0.3
[37] scales_1.2.1 zip_2.2.2 cli_3.5.0
[40] stringi_1.7.8 cachem_1.0.6 promises_1.2.0.1
[43] bslib_0.4.2 ellipsis_0.3.2 generics_0.1.3
[46] vctrs_0.5.1 tools_4.2.2 glue_1.6.2
[49] crosstalk_1.2.0 fastmap_1.1.0 yaml_2.3.6
[52] colorspace_2.0-3 memoise_2.0.1 sass_0.4.4

Could you check what your app's logs say?

@andresrcs , these are the logs. Thank you!

2023-03-14T18:53:05.239337+00:00 shinyapps[6644300]: Loading required package: DBI
2023-03-14T18:53:05.340986+00:00 shinyapps[6644300]: Loading required package: rJava
2023-03-14T18:53:05.810760+00:00 shinyapps[6644300]: Attaching package: ‘gridExtra’
2023-03-14T18:53:05.811033+00:00 shinyapps[6644300]: The following object is masked from ‘package:dplyr’:
2023-03-14T18:53:05.811066+00:00 shinyapps[6644300]:     combine
2023-03-14T18:53:05.814230+00:00 shinyapps[6644300]: Loading required package: ggplot2
2023-03-14T18:53:06.041922+00:00 shinyapps[6644300]: Attaching package: ‘plotly’
2023-03-14T18:53:06.042131+00:00 shinyapps[6644300]: The following object is masked from ‘package:ggplot2’:
2023-03-14T18:53:06.042155+00:00 shinyapps[6644300]:     last_plot
2023-03-14T18:53:06.042339+00:00 shinyapps[6644300]: The following object is masked from ‘package:stats’:
2023-03-14T18:53:06.042357+00:00 shinyapps[6644300]:     filter
2023-03-14T18:53:06.042537+00:00 shinyapps[6644300]: The following object is masked from ‘package:graphics’:
2023-03-14T18:53:06.042546+00:00 shinyapps[6644300]:     layout
2023-03-14T18:53:06.053715+00:00 shinyapps[6644300]: Attaching package: ‘DT’
2023-03-14T18:53:06.053941+00:00 shinyapps[6644300]: The following objects are masked from ‘package:shiny’:
2023-03-14T18:53:06.053953+00:00 shinyapps[6644300]:     dataTableOutput, renderDataTable
2023-03-14T18:53:06.062235+00:00 shinyapps[6644300]: Attaching package: ‘rsconnect’
2023-03-14T18:53:06.062466+00:00 shinyapps[6644300]: The following object is masked from ‘package:shiny’:
2023-03-14T18:53:06.062479+00:00 shinyapps[6644300]:     serverInfo
2023-03-14T18:53:07.038850+00:00 shinyapps[6644300]: Listening on http://127.0.0.1:40427
2023-03-14T18:53:30.638781+00:00 shinyapps[6644300]: Warning: Error in .jcheck: Java Exception <no description because toString() failed>.jcall(conn@jc, "Ljava/sql/Statement;", "createStatement")new("jobjRef", jobj = <pointer: 0x55e2cfc86678>, jclass = "java/lang/Throwable")
2023-03-14T18:53:30.662572+00:00 shinyapps[6644300]:   175: stop
2023-03-14T18:53:30.662616+00:00 shinyapps[6644300]:   174: .jcheck
2023-03-14T18:53:30.662623+00:00 shinyapps[6644300]:   173: .jcall
2023-03-14T18:53:30.662629+00:00 shinyapps[6644300]:   172: .local
2023-03-14T18:53:30.662635+00:00 shinyapps[6644300]:   171: dbSendQuery
2023-03-14T18:53:30.662663+00:00 shinyapps[6644300]:   169: .local
2023-03-14T18:53:30.662669+00:00 shinyapps[6644300]:   168: dbGetQuery
2023-03-14T18:53:30.662674+00:00 shinyapps[6644300]:   163: eventReactiveValueFunc [/srv/connect/apps/test2/app.R#135]
2023-03-14T18:53:30.662685+00:00 shinyapps[6644300]:   119: sales_final_df
2023-03-14T18:53:30.662690+00:00 shinyapps[6644300]:   118: exprFunc
2023-03-14T18:53:30.662695+00:00 shinyapps[6644300]:   117: widgetFunc
2023-03-14T18:53:30.662699+00:00 shinyapps[6644300]:   116: ::
2023-03-14T18:53:30.662711+00:00 shinyapps[6644300]: htmlwidgets
2023-03-14T18:53:30.662716+00:00 shinyapps[6644300]: shinyRenderWidget
2023-03-14T18:53:30.662721+00:00 shinyapps[6644300]:   115: func
2023-03-14T18:53:30.662725+00:00 shinyapps[6644300]:   102: renderFunc
2023-03-14T18:53:30.662730+00:00 shinyapps[6644300]:   101: renderFunc
2023-03-14T18:53:30.662737+00:00 shinyapps[6644300]:    97: renderFunc
2023-03-14T18:53:30.662742+00:00 shinyapps[6644300]:    96: output$sales_final
2023-03-14T18:53:30.662751+00:00 shinyapps[6644300]:    15: <Anonymous>
2023-03-14T18:53:30.662758+00:00 shinyapps[6644300]:    13: fn
2023-03-14T18:53:30.662762+00:00 shinyapps[6644300]:     8: retry
2023-03-14T18:53:30.662768+00:00 shinyapps[6644300]:     7: connect$retryingStartServer
2023-03-14T18:53:30.662786+00:00 shinyapps[6644300]:     6: eval
2023-03-14T18:53:30.662811+00:00 shinyapps[6644300]:     5: eval
2023-03-14T18:53:30.662816+00:00 shinyapps[6644300]:     4: eval
2023-03-14T18:53:30.662828+00:00 shinyapps[6644300]:     3: eval
2023-03-14T18:53:30.662831+00:00 shinyapps[6644300]:     2: eval.parent
2023-03-14T18:53:30.662844+00:00 shinyapps[6644300]:     1: local

I have a similar issue on my machine.

One should be able to reproduce the error using the following snippet (system info follows).

The things I have found are:

  • This bug doesn't seem to exist using openjdk-8, but it begins in openjdk-11 and effects all higher versions that I have tested.
  • The problem seems to be querying SQL from within a reactive. Calls outside the reactive are successful.
  • I have attempted to instantiate the connection in the global environment, within the server, and within the reactive itself. None of these approaches solve the problem.
  • When I examine the connection object, a call to conn@jc yields a string like "Java-Object{net.sourceforge.jtds.jdbc.JtdsConnection@13fee20c}". Within the reactive, this becomes: "Java-Object{}". In particular, the print method for the java object includesrJava::.jstrVal(conn@jc) which appears to throw the error as well when accessed via rJava::.jcheck() (again, only within the reactive).
  • Upon quitting the app runtime, the same connection becomes functional again.

I wonder if the issue has something to do with some multi-threading magic on the shiny backend. A pointer being misplaced? When I look at my jobjoutside of the reactive, I see <pointer: 0x556992f51450>, however when the error throws, I see this:

Java Exception <no description because toString() failed>`<reactive:one>`(...)new("jobjRef", jobj = <pointer: 0x556992f51448>, jclass = "java/lang/Throwable")

I'm not sure if those pointers should match or not. They almost do!

Anyway, I'm hopeful someone with more expertise in shiny particularly can help me with this.

library(shiny)

## We are using JTDS, but this problem does not seem to be driver specific, as I
## tested on Microsoft's JDBC driver (version 12) as well.
drvr <- RJDBC::JDBC(
  driverClass = "net.sourceforge.jtds.jdbc.Driver",
  classPath = Sys.getenv("classPath"))

## Set these environment variables to your username, password, and a connection
## string.
conn <- RJDBC::dbConnect(
  drv = drvr,
  user = Sys.getenv("user"),
  password = Sys.getenv("password"),
  Sys.getenv("connectionString"))

## A simple UI.
ui <- bootstrapPage(plotOutput("plot"))

server <- function(input, output){

  ## This call works.
  x <- RJDBC::dbGetQuery(
    conn = conn,
    statement = "select * from sys.tables")

  one <- reactive({

    ## This call throws an error like the following:
    ##   Warning: Error in .jcheck: Java Exception <no description because
    ##   toString() failed>.jcall(conn@jc, "Z", "getAutoCommit")
    ##   new("jobjRef", jobj = <pointer: 0x564bbbc301d0>, jclass =
    ##   "java/lang/Throwable")
    Y <- RJDBC::dbGetQuery(
      conn = conn,
      statement = "select * from sys.tables")
    return(1)
  })

  ## Some dummy output.
  output$plot <- renderPlot(plot(one()))
}

## Run the application.
shinyApp(ui = ui, server = server)

And my session info:

 R version 4.0.4 (2021-02-15)
 Platform: x86_64-pc-linux-gnu (64-bit)
 Running under: Debian GNU/Linux 11 (bullseye)

 Matrix products: default
 BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

 locale:
  [1] LC_CTYPE=C.UTF-8          LC_NUMERIC=C
  [3] LC_TIME=C.UTF-8           LC_COLLATE=C.UTF-8
  [5] LC_MONETARY=C.UTF-8       LC_MESSAGES=C.UTF-8
  [7] LC_PAPER=C.UTF-8          LC_NAME=C.UTF-8
  [9] LC_ADDRESS=C.UTF-8        LC_TELEPHONE=C.UTF-8
 [11] LC_MEASUREMENT=C.UTF-8    LC_IDENTIFICATION=C.UTF-8

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

 other attached packages:
 [1] shiny_1.7.4

 loaded via a namespace (and not attached):
  [1] Rcpp_1.0.9       crayon_1.5.2     digest_0.6.30    later_1.3.0
  [5] mime_0.12        R6_2.5.1         DBI_1.1.3        jsonlite_1.8.3
  [9] lifecycle_1.0.3  xtable_1.8-4     magrittr_2.0.3   RJDBC_0.2-10
 [13] cachem_1.0.6     rlang_1.1.0      cli_3.4.1        promises_1.2.0.1
 [17] jquerylib_0.1.4  bslib_0.4.2      ellipsis_0.3.2   tools_4.0.4
 [21] httpuv_1.6.6     fastmap_1.1.0    compiler_4.0.4   memoise_2.0.1
 [25] rJava_1.0-8      htmltools_0.5.4  sass_0.4.2

I have a similar problem. The reprex from @ ctrlxctrlc was hugely helpful to tinker with. I confirm I can recreate the issue.

I don't have a full answer, but it seems to be something around having the reactive be invalidated and have to recalculate from within renderPlot.

All of the examples below work on my (Windows) laptop, but I have mixed results when deploying to Posit Connect. Both are using JDK 11.

First made a few changes to the ui.

ui <- bootstrapPage(
  plotOutput("plot"),
  verbatimTextOutput("reactPrint"),
  
  tags$hr(),
  actionButton("updateOutput", "Update Output"),
  actionButton("updateReactive", "Update Reactive")
)

If I put a renderPrint prior to the plot output in the server, both work. This seems to be because the renderPrint will first cause one to be calculated. The renderPlot will use the cached value.

server_v2 <- function(input, output){

# I'm using a different driver and hence different table, but shouldn't matter
  x <- RJDBC::dbGetQuery(conn = conn, statement = "select * from information_schema")

  one <- reactive({
    Y <- RJDBC::dbGetQuery(conn = conn, statement = "select * from information_schema")
    return(1)
  })

  ## have one() cached by the time it gets to plot?
  output$reactPrint <- renderPrint(one())
  output$plot <- renderPlot(plot(one()))

}

If I switch the order of defining the outputs in the server, it no longer works on Connect.

server_v3 <- function(input, output){

  x <- RJDBC::dbGetQuery(conn = conn, statement = "select * from information_schema")

  one <- reactive({
    Y <- RJDBC::dbGetQuery(conn = conn, statement = "select * from information_schema")
    return(1)
  })

  ## Plot first does not work
  output$plot <- renderPlot(plot(one()))
  output$reactPrint <- renderPrint(one())
}

Switching the order back, it loads successfully. If you trigger an update of the render* functions directly (click "Update Output"), it works. If you invalidate the reactive (click "Update Reactive"), output changes to the familiar error message.

server_v4 <- function(input, output){

  x <- RJDBC::dbGetQuery(conn = conn, statement = "select * from information_schema")

  one <- reactive({
    Y <- RJDBC::dbGetQuery(conn = conn, statement = "select * from information_schema")
    return(1 + input$updateReactive)
  })

  output$reactPrint <- renderPrint(one() + input$updateOutput)
  output$plot <- renderPlot(plot(one() + input$updateOutput))

}

This is where it gets particularly weird (hopefully I explain this clearly). If I use renderImage, it will load successfully. Clicking "Update Reactive" == error message. If I refresh the page, no error message even when I click "Update Reactive"

server_v5 <- function(input, output){

  x <- RJDBC::dbGetQuery(conn = conn, statement = "select * from information_schema")

  one <- reactive({
    Y <- RJDBC::dbGetQuery(conn = conn, statement = "select * from information_schema")
    return(1 + input$updateReactive)
  })


  ## Some dummy output.
  output$plot <- renderImage({

    outfile <- tempfile(fileext='.png')

    png(outfile, width=400, height=400)
    plot(one() + input$updateOutput)
    dev.off()

    # Return a list
    list(src = outfile, alt = "This is alternate text")
  }, deleteFile = TRUE)

}

This is starting to feel like a bug, but I'm not sure if it's a shiny issue or a Posit Connect issue or even a RJDBC or rJava issue. Or maybe I'm missing something obvious? This is far as I got. Perhaps this can help someone else peel back the next layer.

I experience the same error in .jcheck() triggered by a simple .jclassPath() call using R 4.3.1 and rJava 1.0.6 on openjdk 11.0.20.1 2023-08-24, as of today. I also had a hard time to come up with a minimal reproducible example, but with the help of the previous code snippets from @ adamsma, I could create one:

library(shiny)
library(rJava)
.jinit()  # Init the JVM

ui <- fluidPage(
  plotOutput("plot"),
  verbatimTextOutput("reactPrint"),
  
  tags$hr(),
  actionButton("updateOutput", "Update Output"),
  actionButton("updateReactive", "Update Reactive")
)

server <- function(input, output, session) {
  x <- .jclassPath()

  one <- reactive({
    Y <- .jclassPath()
    return(1 + input$updateReactive)
  })

  output$plot <- renderPlot(plot(one() + input$updateOutput))
  output$reactPrint <- renderPrint(one()  + input$updateOutput)
}
shinyApp(ui, server)

I reached out to Simon Urbanek, the maintainer of rJava, to discuss if this is more related to rJava or more related to shiny.

My sessionInfo() is:

> library(rJava)
> library(shiny)
> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

time zone: Etc/UTC
tzcode source: system (glibc)

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

other attached packages:
[1] shiny_1.7.5 rJava_1.0-6

loaded via a namespace (and not attached):
 [1] digest_0.6.33   later_1.3.1     R6_2.5.1        httpuv_1.6.11
 [5] fastmap_1.1.1   magrittr_2.0.3  htmltools_0.5.6 lifecycle_1.0.3
 [9] promises_1.2.1  cli_3.6.1       xtable_1.8-4    compiler_4.3.1
[13] mime_0.12       ellipsis_0.3.2  Rcpp_1.0.11     rlang_1.1.1

>.jinit()
> .jcall("java/lang/System", "S", "getProperty", "java.version")
[1] "11.0.20.1"
> .jclassPath()
[1] "/usr/local/lib/R/site-library/rJava/java"
> Sys.getenv("LD_LIBRARY_PATH")
[1] "/usr/lib/jvm/java-1.11.0-openjdk-amd64/lib/server:"
> Sys.getenv("JAVA_HOME")
[1] "/usr/bin/java"

Hi stefanwilhelm
did you get any updates from rJava maintainer?

I am also facing similar kind of error while deploying app in RStudio Connect. it works fine locally but getting below error in RStudio connect.

Please let me know if anyone found any resolution of this issue.

@stefanwilhelm Did you ever get any details about this issue from the rJava maintainer?

Hi everyone,

I'm facing the same error. Are there any updates on this issue?

Thanks in advance.

Best,
Vittoria

Hi everyone,

I've been facing this problem on and off for about a year. It seems this is solved by increasing the java stack size with options(java.parameters = "-Xss3m") or the lowest amount that resolves this issue. This has resolved it locally for me as well in a docker container I use.

Regards,
Egill

I had this problem with docker Shiny containers too. This might already have been mentioned, but a non-ideal workaround is to use observeEvent which seems to work.