Suhov Roman created ARTEMIS-4934:
------------------------------------
Summary: It is necessary to handle a possible error when deleting
a file in the WebTmpCleaner method.java:93
Key: ARTEMIS-4934
URL: https://issues.apache.org/jira/browse/ARTEMIS-4934
Project: ActiveMQ Artemis
Issue Type: Bug
Reporter: Suhov Roman
file:
[https://github.com/apache/activemq-artemis/blob/main/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebTmpCleaner.java]
line: 95
The deleteFolder method needs to handle cases where the file.delete() method
might return false. This can happen when the file does not exist (The file or
directory has already been deleted by another process or manually) or if the
user does not have permission to delete (The current user or process does not
have sufficient rights to delete the file or directory).
To improve code reliability, it is recommended to handle potential errors when
calling file.delete(). This can be done, for example, like this:
_public static final void deleteFolder(final File file) {_
_if (file.isDirectory()) {_
_String[] files = file.list();_
_if (files != null) {_
_for (String path : files) {_
_File f = new File(file, path);_
_deleteFolder(f);_
_}_
_}_
_}_
_if (!file.delete()) {_
_System.err.println("Failed to delete file or directory: " +
file.getAbsolutePath());_
_}_
_}_
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact