Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vrocky opened this issue Jun 5, 2021 · 0 comments

Comments

@vrocky
Copy link

vrocky commented Jun 5, 2021

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 ?

@vrocky vrocky changed the title Error MissingPropertyException while running code through groovy kernel Error MissingPropertyException because of inconsistent scoping of local variables through this groovy kernel Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant