@@ -33,6 +33,9 @@ public abstract class Cursor<T> implements Closeable {
3333 @ Internal
3434 static boolean TRACK_CREATION_STACK ;
3535
36+ @ Internal
37+ static boolean LOG_READ_NOT_CLOSED ;
38+
3639 protected static final int PUT_FLAG_FIRST = 1 ;
3740 protected static final int PUT_FLAG_COMPLETE = 1 << 1 ;
3841
@@ -118,6 +121,7 @@ protected static native long collect004000(long cursor, long keyIfComplete, int
118121 protected final EntityInfo entityInfo ;
119122 protected final BoxStore boxStoreForEntities ;
120123
124+ protected final boolean readOnly ;
121125 protected boolean closed ;
122126
123127 private final Throwable creationThrowable ;
@@ -127,6 +131,7 @@ protected Cursor(Transaction tx, long cursor, EntityInfo entityInfo, BoxStore bo
127131 throw new IllegalArgumentException ("Transaction is null" );
128132 }
129133 this .tx = tx ;
134+ readOnly = tx .isReadOnly ();
130135 this .cursor = cursor ;
131136 this .entityInfo = entityInfo ;
132137 this .boxStoreForEntities = boxStore ;
@@ -146,12 +151,15 @@ protected Cursor(Transaction tx, long cursor, EntityInfo entityInfo, BoxStore bo
146151 @ Override
147152 protected void finalize () throws Throwable {
148153 if (!closed ) {
149- System .err .println ("Cursor was not closed." );
150- if (creationThrowable != null ) {
151- System .err .println ("Cursor was initially created here:" );
152- creationThrowable .printStackTrace ();
154+ // By default only complain about write cursors
155+ if (!readOnly || LOG_READ_NOT_CLOSED ) {
156+ System .err .println ("Cursor was not closed." );
157+ if (creationThrowable != null ) {
158+ System .err .println ("Cursor was initially created here:" );
159+ creationThrowable .printStackTrace ();
160+ }
161+ System .err .flush ();
153162 }
154- System .err .flush ();
155163 close ();
156164 super .finalize ();
157165 }
0 commit comments