twosigma / twosigma/beakerx_kernel_groovy

Error MissingPropertyException because of inconsistent scoping of local variables through this groovy kernel

Open
#16 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
2
Forks
7
PR merge metrics
No merged PRs in 30d

Description

I am trying to run this code on groovy kernel and its give a strange error.

```
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
zipInputFile = new ZipFile(file)
list = entires.toList();
zipInputFile.getInputStream(list.get(0))
```

This is the exception it is giving. while running the same code works with normal execution of groovy script.

```
groovy.lang.MissingPropertyException: No such property: file for class: script1622875172283
at this cell line 3
at com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.runScript(GroovyCodeRunner.java:94)
at com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.call(GroovyCodeRunner.java:59)
at com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.call(GroovyCodeRunner.java:32)

```

Later I found this is happening because this kernel don't share local variables across the cells. But it still share local variable declared at last line.
So if I write,
```
import java.util.zip.ZipEntry
import java.util.zip.ZipFile

String file = "C:\\Users\\user\\.gradle\\caches\\modules-2\\files-2.1\\org.apache.bcel\\bcel\\6.5.0\\79b1975ec0c7a6c1a15e19fb3a58cc4041b4aaea\\bcel-6.5.0.jar"
zipInputFile = new ZipFile(file);

```
in a separate cell 'zipInputFile' will be scoped to next cell.

But when I declare variable mentioning its type. (both ways are valid in groovy)

```
import java.util.zip.ZipEntry
import java.util.zip.ZipFile

String file = "C:\\Users\\user\\.gradle\\caches\\modules-2\\files-2.1\\org.apache.bcel\\bcel\\6.5.0\\79b1975ec0c7a6c1a15e19fb3a58cc4041b4aaea\\bcel-6.5.0.jar"
ZipFile zipInputFile = new ZipFile(file);

```
The zipInputFile will not get scoped to the next cell. Why is this inconsistency ?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.