Env.ServerIsLocal() throws NullReferenceException when DEV env var is unset
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- csharp
- Domain
- mobile-dev, testing-qa
Research direction
Start in test/integration/helpers/Env.cs, read IsTrue and ServerIsLocal, then reproduce with env.json setting DEV to false and the DEV environment variable unset. Run the Android or iOS functional tests, and consider the issue done when an unset DEV value returns false without an exception and the affected fixtures complete setup.
Written by the indexing model from the issue text.
Description
Description
Env.ServerIsLocal() throws a NullReferenceException in CI (and locally, whenever env.json declares "DEV": "false" and the DEV environment variable isn't set), which fails OneTimeSetUp for every integration test fixture that relies on it.
Root cause
test/integration/helpers/Env.cs:
private static bool IsTrue(object val)
{
val = val?.ToString().ToLowerInvariant().Trim();
return val.Equals("true") || val.Equals("1");
}
public static bool ServerIsLocal()
{
Init();
return (_env.ContainsKey("DEV") && IsTrue(_env["DEV"])) || IsTrue(Environment.GetEnvironmentVariable("DEV"));
}
val?.ToString() correctly short-circuits to null when val is null, but the reassigned val is then used in val.Equals(...) unconditionally — so if it's still null, this throws NullReferenceException instead of returning false.
ServerIsLocal() hits this whenever:
env.json's"DEV"value is falsy (e.g."false", as set by CI in.github/workflows/functional-test.yml), so the left side of||isfalse, and- the
DEVenvironment variable is not set (the normal case in CI), soEnvironment.GetEnvironmentVariable("DEV")returnsnullandIsTrue(null)throws.
Impact
Every fixture that calls Env.ServerIsLocal() in its [OneTimeSetUp] fails immediately with NullReferenceException, failing all tests in that fixture. Confirmed in a recent CI run for both platforms, e.g.:
- Android:
Android/Device/App/AppTests.cs,Android/Device/NetworkTests.cs,Android/Device/PerformanceDataTests.cs,Android/Session/Logs/LogcatBroadcastTests.cs - iOS:
IOS/Session/Logs/SyslogBroadcastTests.cs
Stack trace (identical shape on both platforms):
System.NullReferenceException : Object reference not set to an instance of an object.
at Appium.Net.Integration.Tests.helpers.Env.IsTrue(Object val) in .../test/integration/helpers/Env.cs:line 53
at Appium.Net.Integration.Tests.helpers.Env.ServerIsLocal() in .../test/integration/helpers/Env.cs:line 65
at Appium.Net.Integration.Tests.Android.Device.App.AppTests.SetUp() in .../test/integration/Android/Device/App/AppTests.cs:line 21
Reference run: https://github.com/appium/dotnet-client/actions/runs/35200826871 (jobs android-tests and ios-tests).
Note: this bug was previously masked in CI because env.json never actually made it into the test output directory (a separate bug, fixed in #1130) — Env.Init()'s try/catch silently fell back to its default _env dict where DEV is true, so ServerIsLocal() short-circuited on the first operand and never reached the crashing branch. Now that env.json loads correctly, this latent bug surfaces.
Suggested fix
Guard against val being null after the null-conditional chain, e.g.:
private static bool IsTrue(object val)
{
var str = val?.ToString()?.ToLowerInvariant().Trim();
return str == "true" || str == "1";
}
Reproduction
Run the Android or iOS functional test suite in CI (or locally with env.json present and "DEV": "false", and no DEV environment variable set) — any fixture calling Env.ServerIsLocal() fails OneTimeSetUp.
- Dominant language
- C#
- Stars
- 399
- Forks
- 185
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 13
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from appium/dotnet-client
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
appium/dotnet-client#1058 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
appium/dotnet-client#1032 ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
appium/dotnet-client#981 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
appium/dotnet-client#952 · 3 comments · 1 reaction ·
All issues in appium/dotnet-client
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·