Question: I have a server with Linux Mint OS which has a server-side Maven project that reads some environmental variables. 

The environmental variables are declared in /etc/profile.d/my\_env\_vars.sh with:

```
export MY_VAR=/opt/my_app 
export PATH=$MY_VAR:$PATH

```

My server side has a function that when I run it from eclipse (installed in my server) it works fine with no errors.

```
public File convert( byte [] image) throws IOException {
    String filePath = System.getenv("MY_VAR");
    File imageFile = File.createTempFile("TEMP", "tmp", new File(filePath)); 
...
    return imagenFile;
}

```

My client-side also is a maven project. It sends a byte[] image to the function above and the server gives it back a result, but I got the NullPointerException error:

```
java.lang.NullPointerException
java.io.File.<init>(File.java:277)
the second line of my function File imageFile = File.createTempFile("TEMP","temp...

```

Immediately in my server terminal I verified the environmental variable by echo $MY\_VAR and it gives me the correct value (/opt/my\_app)

Why does my function work correctly in my server-side but it gives nullPointerException error in the client-side?

I have tried by declaring the environmental variables in other files as ~/.bashrc ~/.profile /etc/bash.bashrc and nothing works. I read in other post to try to edit ~/.bash\_profile but Linux Mint doesn't have that file.

I really appreciate any advice.

Answer: 
> 
> [Package time](https://golang.org/pkg/time/)
> 
> 
> Monotonic Clocks
> 
> 
> Operating systems provide both a “wall clock,” which is subject to
>  changes for clock synchronization, and a “monotonic clock,” which is
>  not. The general rule is that the wall clock is for telling time and
>  the monotonic clock is for measuring time. Rather than split the API,
>  in this package the Time returned by time.Now contains both a wall
>  clock reading and a monotonic clock reading; later time-telling
>  operations use the wall clock reading, but later time-measuring
>  operations, specifically comparisons and subtractions, use the
>  monotonic clock reading.
> 
> 
> For example, this code always computes a positive elapsed time of
>  approximately 20 milliseconds, even if the wall clock is changed
>  during the operation being timed:
> 
> 
> 
> ```
> start := time.Now()
> ... operation that takes 20 milliseconds ...
> t := time.Now()
> elapsed := t.Sub(start)
> 
> ```
> 
> Other idioms, such as time.Since(start), time.Until(deadline), and
>  time.Now().Before(deadline), are similarly robust against wall clock
>  resets.
> 
> 
> 

Starting with Go 1.9 (released August 24, 2017), Go uses a monotonic clock for durations.

See [Proposal: Monotonic Elapsed Time Measurements in Go](https://golang.org/design/12914-monotonic).
For Go 1.8 and before, the correct timing function is not inside the time package, but instead in the [runtime package](https://golang.org/pkg/runtime/?m=all#nanotime): 

```
func nanotime() int64

```

In order to correctly measure execution time, the following procedure should be used:

```
var startTime = runtime.nanotime()
doSomeHardWork()
var duration = runtime.nanotime() - startTime

```

Unfortunately, the method itself is not documented very well. It emerged in [this issue](https://github.com/Katzenpost/core/issues/6) after a [long discussion if it was really neccessary](https://github.com/golang/go/issues/12914).
For Go 1.9 and newer, refer to Kenny Grant's answer.