@@ -528,10 +528,11 @@ public void closeFileWriter(LoggingFileWriter writer) {
528528 }
529529
530530 static class InnerLoggingFileWriter implements LoggingFileWriter {
531-
531+ private final Object fileLock = new Object ();
532532 private final String fileName ;
533- private final FileOutputStream outputStream ;
534- private final FileOutputStream lockStream ;
533+ private final String lockFileName ;
534+ private FileOutputStream outputStream ;
535+ private FileOutputStream lockStream ;
535536 private int refCount ;
536537
537538 private static final Map <String , InnerLoggingFileWriter > instances ;
@@ -563,14 +564,10 @@ static void removeInstance(final InnerLoggingFileWriter writer) {
563564 }
564565
565566 private InnerLoggingFileWriter (final String fileName , final String lockFileName ) throws FileNotFoundException {
566- this .outputStream = new FileOutputStream (fileName , true );
567- if (lockFileName != null ) {
568- this .lockStream = new FileOutputStream (lockFileName , true );
569- } else {
570- this .lockStream = this .outputStream ;
571- }
572567 this .fileName = fileName ;
568+ this .lockFileName = lockFileName ;
573569 this .refCount = 0 ;
570+ initLock ();
574571 }
575572
576573 public void close () {
@@ -586,10 +583,15 @@ public boolean isValid(final String fileName) {
586583 }
587584
588585 public boolean write (final StringBuilder sb ) {
589- synchronized (this . lockStream ) {
586+ synchronized (fileLock ) {
590587 FileLock lock = null ;
591588 try {
592589 final FileChannel channel = lockStream .getChannel ();
590+ if (!channel .isOpen ()) {
591+ lockStream .close ();
592+ outputStream .close ();
593+ initLock ();
594+ }
593595 lock = channel .lock (0 , Long .MAX_VALUE , false );
594596 outputStream .write (sb .toString ().getBytes ("UTF-8" ));
595597 } catch (Exception e ) {
@@ -607,6 +609,15 @@ public boolean write(final StringBuilder sb) {
607609
608610 return true ;
609611 }
612+
613+ private void initLock () throws FileNotFoundException {
614+ this .outputStream = new FileOutputStream (fileName , true );
615+ if (lockFileName != null ) {
616+ this .lockStream = new FileOutputStream (lockFileName , true );
617+ } else {
618+ this .lockStream = this .outputStream ;
619+ }
620+ }
610621 }
611622
612623 }
@@ -1420,7 +1431,7 @@ private static ObjectMapper getJsonObjectMapper() {
14201431 return jsonObjectMapper ;
14211432 }
14221433
1423- private static final String SDK_VERSION = "3.1.19 " ;
1434+ private static final String SDK_VERSION = "3.1.20 " ;
14241435
14251436 private static final Pattern KEY_PATTERN = Pattern .compile (
14261437 "^((?!^distinct_id$|^original_id$|^time$|^properties$|^id$|^first_id$|^second_id$|^users$|^events$|^event$|^user_id$|^date$|^datetime$)[a-zA-Z_$][a-zA-Z\\ d_$]{0,99})$" ,
0 commit comments