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

rJava::.jinit() terminates R session of RStudio when using R 4.2.0 #11076

Closed
4 tasks done
gk-crop opened this issue Apr 27, 2022 · 9 comments
Closed
4 tasks done

rJava::.jinit() terminates R session of RStudio when using R 4.2.0 #11076

gk-crop opened this issue Apr 27, 2022 · 9 comments
Assignees
Labels

Comments

@gk-crop
Copy link

@gk-crop gk-crop commented Apr 27, 2022

When calling rJava::.jinit() in the RStudio console then RStudio shows the dialog "R Session Aborted" (R encountered a fatal error).
This happens with R 4.2.0, but not with previous R versions.

In plain R or when sourcing the command as local job in RStudio there is no error.

System details

RStudio Edition : Desktop
RStudio Version : 2022.02.1 Build 461
OS Version      :  Windows 10 Pro, 21H2, 64 bit
R Version       :  4.2.0 (2022-04-22 ucrt, x86_64-w64-mingw32/x64)
Java Version  : 11.0.12 (Temurin - Eclipse Foundation amd64) 

Steps to reproduce the problem

Start RStudio
execute in the console:

install.packages("rJava") # if rJava is not installed yet
rJava::.jinit()

Alternatives:

  • create a file checkJava.R that contains rJava::.jinit()
  • type source("checkJava.R")

Describe the problem in detail

When executing the code or sourcing it, RStudio reports that the R session aborted.

Describe the behavior you expected

R session should not crash.

  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
    diagnostics-report.txt
@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 27, 2022

Thanks for the bug report -- I can reproduce this as well. The crash is happening in a call to do_getlocale() in R:

image

For whatever reason, this is crashing RStudio:

Sys.getlocale(cateogry = "LC_MESSAGES")

As a temporary workaround, you could use the following:


replacement <- function(category = "LC_ALL") {
  
  if (identical(category, "LC_MESSAGES"))
    return("")
  
  category <- match(category, .LC.categories)
  if (is.na(category)) 
    stop("invalid 'category' argument")
  .Internal(Sys.getlocale(category))
  
}

base <- asNamespace("base")
environment(replacement) <- base
unlockBinding("Sys.getlocale", base)
assign("Sys.getlocale", replacement, envir = base)
lockBinding("Sys.getlocale", base)

library(rJava)
rJava::.jinit()

We'll need to investigate further.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 28, 2022

It looks like this happens because the RStudio R session is compiled with MSVC, rather than gcc. For MSVC, an invalid parameter handler is registered as described in:

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/invalid-parameter-functions?view=msvc-170

It seems like this handler is not registered by default for applications built using MinGW / gcc, so crashes are not triggered in such a case.

If we wanted to match the behavior of R, we would likely want to disable this by registering a no-op handler via _set_invalid_parameter_handler() (or make sure behavior configurable in some way).

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Apr 28, 2022

There is now a fix available in R 4.2.0-patched, as available from:

https://cran.r-project.org/bin/windows/base/rpatched.html

Thanks to Tomas Kalibera for taking a look so quickly.

@mikebessuille
Copy link
Contributor

@mikebessuille mikebessuille commented May 2, 2022

Leaving this in SW for now, hoping this is fixed in R and we can just re-test it.

@jgutman
Copy link
Contributor

@jgutman jgutman commented May 9, 2022

Tested in Windows 10 running R version 4.2.0 Patched (2022-05-06 r82327 ucrt) with RStudio Desktop 2022.6.0.374 and rJava 1.0.6.

rJava::.jinit() runs successfully with the latest R patch

@hsiaoyi0504
Copy link

@hsiaoyi0504 hsiaoyi0504 commented Jul 6, 2022

I meet the issue again for R4.2.1 patch.

@GabryS3
Copy link

@GabryS3 GabryS3 commented Jul 13, 2022

Hi, is this issue been fixed in the latest R (R 4.2.1 - June, 2022) & RStudio (2022.07.0+548) versions??
I also had an issue of RStudio crashing every time I load the xlsx package with R version 4.2.0 & RStudio version 2022.02.3....I am not sure if this is related...but I would love to know whether this is fixed in the latest R/RStudio versions before updating...
Thanks
Gabriella

@Phylloxera
Copy link

@Phylloxera Phylloxera commented Jul 22, 2022

Hi, is there a patched version for Mac or just windows?

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 22, 2022

This issue specifically tracks the issue of using rJava with R 4.2.0 on Windows; if you're having trouble with rJava with a different platform (e.g. macOS) then please file a new issue with more details.

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

No branches or pull requests

9 participants