{"record":{"id":"d85e263ed50787fd","repo":"brettwooldridge/HikariCP","slug":"cannot-find-property-file-propertyfilename","errorCode":null,"errorMessage":"Cannot find property file: ${propertyFileName}","messagePattern":"Cannot find property file: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/zaxxer/hikari/HikariConfig.java","lineNumber":1210,"sourceCode":"            }\n            LOGGER.debug(\"{}{}\", (prop + \"................................................\").substring(0, 32), value);\n         }\n         catch (Exception e) {\n            // continue\n         }\n      }\n   }\n\n   private void loadProperties(String propertyFileName)\n   {\n      try (final var is = openPropertiesInputStream(propertyFileName)) {\n         if (is != null) {\n            var props = new Properties();\n            props.load(is);\n            PropertyElf.setTargetFromProperties(this, props);\n         }\n         else {\n            throw new IllegalArgumentException(\"Cannot find property file: \" + propertyFileName);\n         }\n      }\n      catch (IOException io) {\n         throw new RuntimeException(\"Failed to read property file\", io);\n      }\n   }\n\n   private InputStream openPropertiesInputStream(String propertyFileName) throws FileNotFoundException {\n      final var propFile = new File(propertyFileName);\n      if (propFile.isFile()) {\n         return new FileInputStream(propFile);\n      }\n      var propertiesInputStream = this.getClass().getResourceAsStream(propertyFileName);\n      if (propertiesInputStream == null) {\n        propertiesInputStream = this.getClass().getClassLoader().getResourceAsStream(propertyFileName);\n      }\n      return propertiesInputStream;\n   }","sourceCodeStart":1192,"sourceCodeEnd":1228,"githubUrl":"https://github.com/brettwooldridge/HikariCP/blob/a4d93f4f85517f90e632b795486d7102e933d7ff/src/main/java/com/zaxxer/hikari/HikariConfig.java#L1192-L1228","documentation":"When HikariConfig is constructed with a property file name, loadProperties tries (in order) the filesystem, the class resource, and the classloader resource; if all return null it throws IllegalArgumentException 'Cannot find property file: <name>'. The name must be a path that resolves in at least one of those locations — a bare name is not implicitly prefixed with a directory.","triggerScenarios":"new HikariConfig(\"app.properties\") when the file is neither in the working directory nor on the classpath; wrong relative path (file sits in src/main/resources but the run directory differs); misspelled file name; path with a leading slash that mismatches the classloader lookup; packaging where the resource is filtered out.","commonSituations":"Working-directory assumptions breaking when running a jar vs from IDE; resources placed under a subfolder (src/main/resources/config/db.properties) but referenced as db.properties; Maven resource filtering or shade plugin excluding the file; the file present at build time but not in the Docker image layer.","solutions":["Verify where the file actually is at runtime: check the jar contents (jar tf) or the working directory of the process","Reference classpath resources with the correct relative path from the resources root, e.g. new HikariConfig(\"/config/db.properties\") or the matching non-slash form","For filesystem files, use an absolute or verified relative path from the actual working directory","Alternatively load the Properties yourself (classloader resource) and pass them to new HikariConfig(Properties) — this sidesteps HikariCP's lookup rules"],"exampleFix":"// before\nHikariConfig cfg = new HikariConfig(\"db.properties\"); // file is in src/main/resources/config/ -> not found\n\n// after\nHikariConfig cfg = new HikariConfig(\"/config/db.properties\");\n// or explicit classpath loading\ntry (var is = HikariConfig.class.getClassLoader().getResourceAsStream(\"config/db.properties\")) {\n   Properties props = new Properties();\n   props.load(is);\n   HikariConfig cfg2 = new HikariConfig(props);\n}","handlingStrategy":"validation","validationCode":"String name = \"/config/hikari.properties\";\nboolean found = new java.io.File(name).isFile()\n    || HikariConfig.class.getResource(name) != null\n    || HikariConfig.class.getClassLoader().getResource(name) != null;\nif (!found) throw new IllegalStateException(\"HikariCP property file not found in fs/classpath: \" + name);\nnew HikariConfig(name);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer new HikariConfig(Properties) with your own resource loading — you control lookup and error messages","Verify resource paths inside the built artifact (jar tf) in CI","Use paths relative to the classpath root consistently (with/without leading slash)"],"tags":["hikaricp","configuration","properties-file","classpath","resource-loading"],"backgroundTag":null,"analyzedSha":"a4d93f4f85517f90e632b795486d7102e933d7ff","analyzedAt":"2026-08-14T12:11:37.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}