Add a null check to method HttpStaticFileServerHandler.sendListing (#10040)
Motivation: java.io.File.listFiles() may return null and cause a unexpected NPE. Modification: Extract a local variable from the return value of File.listFiles() and do a null check. Result: Fix the potential NPE.
This commit is contained in:
parent
dcd62c2598
commit
125cd9552d
@ -286,7 +286,9 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
|
||||
.append("<ul>")
|
||||
.append("<li><a href=\"../\">..</a></li>\r\n");
|
||||
|
||||
for (File f: dir.listFiles()) {
|
||||
File[] files = dir.listFiles();
|
||||
if (files != null) {
|
||||
for (File f: files) {
|
||||
if (f.isHidden() || !f.canRead()) {
|
||||
continue;
|
||||
}
|
||||
@ -302,6 +304,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
|
||||
.append(name)
|
||||
.append("</a></li>\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
buf.append("</ul></body></html>\r\n");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user