File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -144,7 +144,7 @@ public final class PythonContext {
144
144
private final AsyncHandler handler ;
145
145
146
146
// A thread-local to store the full path to the currently active import statement, for Jython compat
147
- private final ThreadLocal <Stack <String >> currentImport = ThreadLocal . withInitial (() -> new Stack <>() );
147
+ private final ThreadLocal <Stack <String >> currentImport = new ThreadLocal <>();
148
148
149
149
public PythonContext (PythonLanguage language , TruffleLanguage .Env env , PythonCore core ) {
150
150
this .language = language ;
@@ -729,7 +729,9 @@ public boolean isPyFileInLanguageHome(TruffleFile path) {
729
729
@ TruffleBoundary
730
730
public String getCurrentImport () {
731
731
Stack <String > ci = currentImport .get ();
732
- if (ci .isEmpty ()) {
732
+ if (ci == null ) {
733
+ return "" ;
734
+ } else if (ci .isEmpty ()) {
733
735
return "" ;
734
736
} else {
735
737
return ci .peek ();
@@ -738,11 +740,17 @@ public String getCurrentImport() {
738
740
739
741
@ TruffleBoundary
740
742
public void pushCurrentImport (String object ) {
741
- currentImport .get ().push (object );
743
+ Stack <String > ci = currentImport .get ();
744
+ if (ci == null ) {
745
+ ci = new Stack <>();
746
+ currentImport .set (ci );
747
+ }
748
+ ci .push (object );
742
749
}
743
750
744
751
@ TruffleBoundary
745
752
public void popCurrentImport () {
753
+ assert currentImport .get () != null && currentImport .get ().peek () != null : "invalid popCurrentImport without push" ;
746
754
currentImport .get ().pop ();
747
755
}
748
756
}
You can’t perform that action at this time.
0 commit comments