You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My PostgreSQL DB table has a field called "committed_at of type "DATE", which I map to a POJO with a field called committedAt of type "LocalDate". I forgot to add the custom converter for this, but I was expecting a warning about not being able to assign the field. Instead, it silently assigned the "java.sql.Date" object to a field of type "java.time.LocalDate", meaning attempts to call methods on it will crash the JVM.
Here is my mostly self-contained example:
public class Main {
public static class Crime {
public LocalDate committedAt;
public Double latitude;
public Double longitude;
public String location;
public String type;
}
public static void main(String[] args) {
PGSimpleDataSource d = new PGSimpleDataSource();
d.setUser("postgres");
d.setPassword("password");
d.setServerName("localhost");
d.setPortNumber(5432);
d.setDatabaseName("crime_db");
Sql2o sql2o = new Sql2o(d);
String sql = "SELECT committed_at committedAt, coordinates[0] latitude, coordinates[1] longitude, location, type FROM crimes";
try(Connection con = sql2o.open()) {
Crime crime = con.createQuery(sql).executeAndFetchFirst(Crime.class);
LocalDate date = crime.committedAt;
System.out.println(date.getClass().getName());
System.out.println(date.getYear());
}
}
}
This outputs:
Java.sql.Date
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000638331f3, pid=15832, tid=0x00000000000004b4
#
# JRE version: Java(TM) SE Runtime Environment (8.0_131-b11) (build 1.8.0_131-b11)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.131-b11 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# V [jvm.dll+0x2031f3]
Edit: This seems like it might be related to issue #206
The text was updated successfully, but these errors were encountered:
DanStout
changed the title
Access Violation: Sql2o sets field to object of wrong type without warning; crashes JVM
Access Violation: Sql2o assigns object of wrong type to field without warning; crashes JVM
Jun 8, 2017
DanStout
changed the title
Access Violation: Sql2o assigns object of wrong type to field without warning; crashes JVM
Access Violation: Sql2o assigns object to field of wrong type without warning; crashes JVM
Jun 8, 2017
This looks to be related to the change to the setter functionality to use sun.misc.Unsafecommit. Have you tried to use version 1.5.4 or Jodas Localdate with your existing version?
It sounds very possible that it was caused by the use of Unsafe. I don't have any interest in using Joda's version of LocalDate, and that isn't really the issue - the issue is that this crashed the JVM instead of throwing a runtime exception when it attempted to map a field to an unknown type.
My PostgreSQL DB table has a field called "committed_at of type "DATE", which I map to a POJO with a field called committedAt of type "LocalDate". I forgot to add the custom converter for this, but I was expecting a warning about not being able to assign the field. Instead, it silently assigned the "java.sql.Date" object to a field of type "java.time.LocalDate", meaning attempts to call methods on it will crash the JVM.
Here is my mostly self-contained example:
This outputs:
(The rest of the error is omitted)
Relevant build.gradle stuff:
Edit: This seems like it might be related to issue #206
The text was updated successfully, but these errors were encountered: