英文:
AWS Lambda Java runtime: Home directory does not exist?
问题
在 AWS Lambda Java 运行时(Java 11 或 Java 8)中运行 Java 代码时,似乎设置了 系统属性 user.home
,但该目录似乎不存在(根据 File.exists()
)。这是预期行为还是一个错误?
以下是演示此问题的代码片段:
File userHome = new File(System.getProperty("user.home"));
LOG.info("user.home: {} exists: {}", userHome, userHome.exists());
File javaIoTmpdir = new File(System.getProperty("java.io.tmpdir"));
LOG.info("java.io.tmpdir: {} exists: {}", javaIoTmpdir, javaIoTmpdir.exists());
以下是相应的日志输出:
user.home: /home/sbx_user1051 exists: false
java.io.tmpdir: /tmp exists: true
user.home
系统属性被设置为指向一个不存在的目录似乎有些令人惊讶。或者我在这里忽视了一些明显的东西吗?
背景:我在尝试使用一个第三方库时遇到了这个问题,该库在 user.home
目录不存在的情况下无法正常工作。
英文:
When running Java code in the AWS Lambda Java runtime (Java 11 or Java 8), it seems that the system property user.home
is set, but the directory does not seem to exist (according to File.exists()
). Is this expected or a bug?
Here's a code snippet to demonstrate the issue:
File userHome = new File(System.getProperty("user.home"));
LOG.info("user.home: {} exists: {} ", userHome, userHome.exists());
File javaIoTmpdir = new File(System.getProperty("java.io.tmpdir"));
LOG.info("java.io.tmpdir: {} exists: {} ", javaIoTmpdir, javaIoTmpdir.exists());
And here is the corresponding log output:
user.home: /home/sbx_user1051 exists: false
java.io.tmpdir: /tmp exists: true
It seems somewhat surprising that user.home
system property would be set to point to a directory that does not exist. Or am I overlooking something obvious here?
Background: I ran into this problem while trying to use a third-party library that does not work correctly in the case where the user.home
directory does not exist.
专注分享java语言的经验与见解,让所有开发者获益!
评论