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

NullPointerException in SketchCode.getDocumentText() #4555

Closed
JJ-Atkinson opened this Issue Jul 1, 2016 · 5 comments

Comments

Projects
None yet
4 participants
@JJ-Atkinson

JJ-Atkinson commented Jul 1, 2016

When I run tweak mode all is well. But when I try to run normal after running tweak mode, it throws this error:

Exception in thread "Thread-58" java.lang.NullPointerException
    at processing.app.SketchCode.getDocumentText(SketchCode.java:228)
    at processing.app.ui.Editor.prepareRun(Editor.java:2716)
    at processing.mode.java.JavaEditor.prepareRun(JavaEditor.java:1781)
    at processing.mode.java.JavaEditor$34.run(JavaEditor.java:1095)
    at java.lang.Thread.run(Thread.java:745)

I'm running processing 3.1.1 on windows 10.

Please note this only happens in sketches with multiple files.

@galsasson

This comment has been minimized.

Show comment
Hide comment
@galsasson

galsasson Jul 4, 2016

Contributor

Can you please provide an example sketch that produces this error?

Contributor

galsasson commented Jul 4, 2016

Can you please provide an example sketch that produces this error?

@JJ-Atkinson

This comment has been minimized.

Show comment
Hide comment
@JJ-Atkinson

JJ-Atkinson Jul 5, 2016

@galsasson Sure, here you go:

Tab 1

void setup() {
  size(300, 300);
}

void draw() {
  otherFunc();
}

Tab 2

void otherFunc() {
  background(50);
  text("Hi!", 30, 30);
}

Run this in normal mode, then run it in tweak mode, then try to run it in normal mode again, and you will get the above error.

JJ-Atkinson commented Jul 5, 2016

@galsasson Sure, here you go:

Tab 1

void setup() {
  size(300, 300);
}

void draw() {
  otherFunc();
}

Tab 2

void otherFunc() {
  background(50);
  text("Hi!", 30, 30);
}

Run this in normal mode, then run it in tweak mode, then try to run it in normal mode again, and you will get the above error.

@JJ-Atkinson

This comment has been minimized.

Show comment
Hide comment
@JJ-Atkinson

JJ-Atkinson Jul 6, 2016

I went poking around in the source, and found JavaEditor.stopTweakMode() and JavaEditor.setTabContents(), both of which set the document to null.

protected void stopTweakMode(List<List<Handle>> handles) {
  // lots of code skipped 
  /* Wild Hack: set document to null so the text editor will refresh
      the program contents when the document tab is being clicked */
  sketch.getCode(i).setDocument(null);
  // ...
protected void setTabContents(String tabFilename, String code) {
  // lots of code skipped 
  tab.setDocument(null);
  // ...

Maybe one of thees is the culprit?

JJ-Atkinson commented Jul 6, 2016

I went poking around in the source, and found JavaEditor.stopTweakMode() and JavaEditor.setTabContents(), both of which set the document to null.

protected void stopTweakMode(List<List<Handle>> handles) {
  // lots of code skipped 
  /* Wild Hack: set document to null so the text editor will refresh
      the program contents when the document tab is being clicked */
  sketch.getCode(i).setDocument(null);
  // ...
protected void setTabContents(String tabFilename, String code) {
  // lots of code skipped 
  tab.setDocument(null);
  // ...

Maybe one of thees is the culprit?

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Jul 29, 2016

Member

@JakubValtar is this a regression from the Editor/Document/Undo changes?

Member

benfry commented Jul 29, 2016

@JakubValtar is this a regression from the Editor/Document/Undo changes?

@JakubValtar

This comment has been minimized.

Show comment
Hide comment
@JakubValtar

JakubValtar Jul 29, 2016

Contributor

@benfry Yes, this is my doing. I'll be fixing it this week.

Contributor

JakubValtar commented Jul 29, 2016

@benfry Yes, this is my doing. I'll be fixing it this week.

@benfry benfry changed the title from Running in tweak mode prevents normal mode from working to NullPointerException in SketchCode.getDocumentText() Jul 29, 2016

@benfry benfry added the high label Jul 29, 2016

JakubValtar added a commit to JakubValtar/processing that referenced this issue Aug 1, 2016

Prevent NPEs when tab document is null
JavaMode visits all tabs on sketch load to extract breakpoints, so doc
is always set (except when running Tweak mode; it sets docs to null to
force reload). Other modes have null docs until the tabs are visited
manually.

Fixes #4555

@benfry benfry closed this in #4596 Aug 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment