@@ -122,8 +122,13 @@ private void triggerInitialEvents(Path root) throws IOException, FilenameExcepti
122122 if (Files .isDirectory (path )) {
123123 triggerInitialEvents (path );
124124 } else {
125- path = WorldEdit .getInstance ().getSafeOpenFile (null , schematicRoot .toFile (), schematicRoot .relativize (path ).toString (), null ).toPath ();
126- eventConsumer .accept (new FileCreatedEvent (path ));
125+ try {
126+ path = WorldEdit .getInstance ().getSafeOpenFile (null , schematicRoot .toFile (), schematicRoot .relativize (path ).toString (), null ).toPath ();
127+ eventConsumer .accept (new FileCreatedEvent (path ));
128+ } catch (FilenameException e ) {
129+ // Invalid filename, warn but don't fail.
130+ LOGGER .warn ("Illegal file detected" , e );
131+ }
127132 }
128133 }
129134 }
@@ -182,17 +187,22 @@ public void start(Consumer<DirEntryChangeEvent> eventConsumer) {
182187 path = parentPath .resolve (path );
183188
184189 if (kind .equals (StandardWatchEventKinds .ENTRY_CREATE )) {
185- path = WorldEdit .getInstance ().getSafeOpenFile (null , schematicRoot .toFile (), schematicRoot .relativize (path ).toString (), null ).toPath ();
186-
187- if (Files .isDirectory (path )) { // new subfolder created, create watch for it
188- try {
189- registerFolderWatcher (path );
190- triggerInitialEvents (path );
191- } catch (IOException | FilenameException e ) {
192- LOGGER .error (e );
190+ try {
191+ path = WorldEdit .getInstance ().getSafeOpenFile (null , schematicRoot .toFile (), schematicRoot .relativize (path ).toString (), null ).toPath ();
192+
193+ if (Files .isDirectory (path )) { // new subfolder created, create watch for it
194+ try {
195+ registerFolderWatcher (path );
196+ triggerInitialEvents (path );
197+ } catch (IOException | FilenameException e ) {
198+ LOGGER .error (e );
199+ }
200+ } else { // new file created
201+ eventConsumer .accept (new FileCreatedEvent (path ));
193202 }
194- } else { // new file created
195- eventConsumer .accept (new FileCreatedEvent (path ));
203+ } catch (FilenameException e ) {
204+ // Invalid filename, warn but don't fail.
205+ LOGGER .warn ("Illegal file detected" , e );
196206 }
197207 } else if (kind .equals (StandardWatchEventKinds .ENTRY_DELETE )) {
198208 // When we are notified about a deleted entry, we can't simply ask the filesystem
@@ -218,7 +228,7 @@ public void start(Consumer<DirEntryChangeEvent> eventConsumer) {
218228 }
219229 }
220230 }
221- } catch (ClosedWatchServiceException | FilenameException ignored ) {
231+ } catch (ClosedWatchServiceException ignored ) {
222232 // Watch service closed, exit
223233 }
224234 LOGGER .debug ("RecursiveDirectoryWatcher::EventConsumer exited" );
0 commit comments