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 when creating tempfiles in rspec #4433

Closed
synth opened this Issue Jan 10, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@synth

synth commented Jan 10, 2017

JRuby throws a NullPointerException in Rspec tests when creating tempfiles. The issue occurs when uploading fixture files using the same file across multiple describe blocks.

Here is the test code that exhibits the issue:

require 'spec_helper'

describe 'Tempfile' do
  let(:file) { fixture_file_upload(Rails.root.join('spec/fixtures/file_1.txt').to_s) }

  describe 'test' do
    describe '1' do
      it { expect{file}.to_not raise_exception }
    end

    describe '2' do
      # Test will pass if before block is uncommented
      # Or if config.order = "random" is commented in spec_helper
      # before { ActionMailer::Base.deliveries.clear }
      it { expect{file}.to_not raise_exception }
    end

  end  

end

I've created a sample app here https://github.com/synth/jruby-rspec-tempfile-bug
I've also got multiple builds being tested on TravisCI here: https://travis-ci.org/synth/jruby-rspec-tempfile-bug

As you can see, some versions of MRI and JRuby are passing and some aren't. In particular, JRuby v9.1.5.0 is where I first encountered this bug. While this test also doesn't pass in MRI, its in JRuby that I experience the NullPointerException which is why I'm reporting it here. (I think MRI is failing due to some other dependency issue or something...)

As noted in the README of the sample app, the bug appears when two conditions are true:

  1. Rspec.config.order = "random"
  2. ActionMailer::Base.deliveries is not cleared in a before block

Very weird, I know. I would bet those things are somehow triggering something else under the covers though.

Let me know if I can provide more information or if I should go about creating a better test case.

Thanks!

@kares

This comment has been minimized.

Show comment
Hide comment
@kares

kares Jan 10, 2017

Member

confirmed on master, the shortened backtrace points to Tempfile :

  1) Tempfile test 2 
     Failure/Error: it { expect{file}.to_not raise_exception }
       expected no Exception, got java.lang.NullPointerException with backtrace:
         # org.jruby.ext.tempfile.Tempfile$TempfileCallback.call(Tempfile.java:153)
         # org.jruby.runtime.CallBlock19.doYield(CallBlock19.java:110)
         # org.jruby.runtime.BlockBody.yield(BlockBody.java:120)
         # org.jruby.runtime.Block.yieldValues(Block.java:183)
         # org.jruby.ir.instructions.YieldInstr.interpret(YieldInstr.java:80)
Member

kares commented Jan 10, 2017

confirmed on master, the shortened backtrace points to Tempfile :

  1) Tempfile test 2 
     Failure/Error: it { expect{file}.to_not raise_exception }
       expected no Exception, got java.lang.NullPointerException with backtrace:
         # org.jruby.ext.tempfile.Tempfile$TempfileCallback.call(Tempfile.java:153)
         # org.jruby.runtime.CallBlock19.doYield(CallBlock19.java:110)
         # org.jruby.runtime.BlockBody.yield(BlockBody.java:120)
         # org.jruby.runtime.Block.yieldValues(Block.java:183)
         # org.jruby.ir.instructions.YieldInstr.interpret(YieldInstr.java:80)

@kares kares added this to the JRuby 9.1.7.0 milestone Jan 10, 2017

@kares kares self-assigned this Jan 10, 2017

@kares

This comment has been minimized.

Show comment
Hide comment
@kares

kares Jan 10, 2017

Member

do have a fix that resolves the NPE and everything seems fine. for whatever reason I'm failing to extract a reproducable isolated test-case. maybe it has to do with rspec's patching, will likely close this without a test.

Member

kares commented Jan 10, 2017

do have a fix that resolves the NPE and everything seems fine. for whatever reason I'm failing to extract a reproducable isolated test-case. maybe it has to do with rspec's patching, will likely close this without a test.

@kares kares closed this in 886ec64 Jan 10, 2017

@synth

This comment has been minimized.

Show comment
Hide comment
@synth

synth Jan 10, 2017

Thanks for closing this out so fast! Any advice on what to do in the meanwhile until the 9.1.7.0 release is cut?

synth commented Jan 10, 2017

Thanks for closing this out so fast! Any advice on what to do in the meanwhile until the 9.1.7.0 release is cut?

@synth

This comment has been minimized.

Show comment
Hide comment
@synth

synth Jan 12, 2017

I see 9.1.7.0 was cut yesterday, disregard, thanks!

synth commented Jan 12, 2017

I see 9.1.7.0 was cut yesterday, disregard, thanks!

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