如何在AWS Lambda的Java代码中启用断言?

huangapple go评论69阅读模式
英文:

How to enable assertions in AWS Lambda Java code?

问题

如何在AWS Lambda的Java代码中启用断言?

基本上,我希望AWS Lambda在Java代码中考虑我的断言语句。

英文:

How to enable assertions in AWS Lambda Java code ?

Basically I want AWS Lambda to take into account my assert statements in Java code.

答案1

得分: 2

如Bjorn所提到的,您需要启用-enableassertions

可以通过使用自定义运行时而不是默认的AWS来实现。这里有一个使用自定义运行时的示例 - https://github.com/andthearchitect/aws-lambda-java-runtime

注意:还有一个选项JAVA_TOOL_OPTIONS,在尝试检查自定义运行时之前,请尝试使用它。

另一个选项可以是将断言替换为类似以下的内容:

if (!condition) {
    throw new AssertionError();
}

如果是您自己的代码,第二个选项听起来更好。

英文:

As mentioned by Bjorn you have too enable -enableassertions.

It is possible to have them but with using custom runtime not the default AWS.
Here is one example of having custom runtime - https://github.com/andthearchitect/aws-lambda-java-runtime

Note: There is an option JAVA_TOOL_OPTIONS, please give it a try before checking custom runtime.

Another option could be just replace asserting with something like .

if (!condition) {
    throw new AssertionError();
}

If it is your own code second options sounds better.

答案2

得分: 1

启用断言需要使用-enableassertions启动命令。不幸的是,在AWS Lambda中无法向JVM传递参数,只支持环境变量。回答你的问题:不,这是不可能的。

英文:

To enable assertions assertions you need to use the -enableassertions startup command. Unfortunately you cannot give arguments to the JVM with AWS Lambda. Only environment variables are supported. To answer your question: no this is not possible.

huangapple
  • 本文由 发表于 2020年8月31日 01:49:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63660403.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定