{"record":{"id":"f6ebb03dffb34cad","repo":"eclipse-vertx/vert.x","slug":"cannot-read-hosts-file-file-getabsolutepath","errorCode":null,"errorMessage":"Cannot read hosts file ${file.getAbsolutePath()}","messagePattern":"Cannot read hosts file (.+?)","errorType":"exception","errorClass":"io.vertx.core.VertxException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/dns/impl/DnsAddressResolverProvider.java","lineNumber":241,"sourceCode":"  private void ensureHostsFileFresh(long refreshPeriodNanos) {\n    long prev = refreshTimestamp.get();\n    long now = System.nanoTime();\n    if ((now - prev) >= refreshPeriodNanos && refreshTimestamp.compareAndSet(prev, now)) {\n      refreshHostsFile();\n    }\n  }\n\n  private void refreshHostsFile() {\n    HostsFileEntries entries;\n    if (hostsPath != null) {\n      File file = vertx.fileResolver().resolve(hostsPath).getAbsoluteFile();\n      try {\n        if (!file.exists() || !file.isFile()) {\n          throw new IOException();\n        }\n        entries = HostsFileParser.parse(file);\n      } catch (IOException e) {\n        throw new VertxException(\"Cannot read hosts file \" + file.getAbsolutePath());\n      }\n    } else if (hostsValue != null) {\n      try {\n        entries = HostsFileParser.parse(new StringReader(hostsValue.toString()));\n      } catch (IOException e) {\n        throw new VertxException(\"Cannot read hosts config \", e);\n      }\n    } else {\n      entries = HostsFileParser.parseSilently();\n    }\n    parsedHostsFile = entries;\n  }\n\n  private static class ResolverRegistration {\n    private final io.netty.resolver.AddressResolver<InetSocketAddress> resolver;\n    private final EventLoop executor;\n    ResolverRegistration(io.netty.resolver.AddressResolver<InetSocketAddress> resolver, EventLoop executor) {\n      this.resolver = resolver;","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/dns/impl/DnsAddressResolverProvider.java#L223-L259","documentation":"Runtime error while refreshing the hosts file used for local resolution: the configured hosts file path either does not exist, is not a regular file, or could not be parsed by HostsFileParser (IOException). The VertxException aborts the periodic refresh triggered after the refresh period elapsed.","triggerScenarios":"Thrown at vertx-core/src/main/java/io/vertx/core/dns/impl/DnsAddressResolverProvider.java:241 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the hosts path configured via AddressResolverOptions.setHostsPath exists and is readable","Fix permissions or path typos; the refresh is retried on the next period","Use setHostsValue to supply hosts entries inline if no file is available"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}