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

NPE in BoxedObjectArray.length #798

Closed
scabug opened this issue Apr 23, 2008 · 7 comments
Closed

NPE in BoxedObjectArray.length #798

scabug opened this issue Apr 23, 2008 · 7 comments
Labels

Comments

@scabug
Copy link

scabug commented Apr 23, 2008

The following code generates cause BoxedObjectArray.length to throw an NPE.

To reproduce run against a large enough directory tree

import java.io.File

object Main {

  def walk(top: File) : Unit = {
      if (top.isDirectory) {
          for (fn <- top.listFiles) walk(fn)
      } else {
          println(top)
      }
  }
  def main(args: Array[String]) = {
    if (args.length == 0) {
        println("No dirname")
        exit(1)
    }
    
    val f = new File(args(0))
    
    walk(f)
  }
}
@scabug
Copy link
Author

scabug commented Apr 23, 2008

Imported From: https://issues.scala-lang.org/browse/SI-798?orig=1
Reporter: Yoel Jacobsen (yoeljacobsen)
Attachments:

  • err (created on Feb 14, 2009 10:33:40 AM UTC, 1885 bytes)

@scabug
Copy link
Author

scabug commented Apr 29, 2008

@lrytz said:
Can't reproduce it (on a directory tree with millions of entries).

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone next_bugfix deleted

@scabug
Copy link
Author

scabug commented Feb 14, 2009

Martin Kneissl (mkneissl) said:
I can reproduce this on my machine:

  • Scala 2.7.3.final
  • java version "1.6.0_10"
    Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
    Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)
  • Microsoft Windows XP [Version 5.1.2600]

See also attached stack trace.

@scabug
Copy link
Author

scabug commented Feb 14, 2009

Martin Kneissl (mkneissl) said:
Stack trace

@scabug
Copy link
Author

scabug commented Feb 14, 2009

@paulp said:
It's because you're using a null value in a generator (isDirectory == true does not guarantee listFiles != null.) Try it this way:

      def files() = top.listFiles match {
        case null => Nil
        case xs   => xs.toList
      }
      if (top.isDirectory) {
          for (fn <- files) walk(fn)
      } else {
          println(top)
      }

@scabug
Copy link
Author

scabug commented Feb 14, 2009

Martin Kneissl (mkneissl) said:
Confirmed. Thanks.

File.listFiles returns null for example when the process has no permissions to list the files of the directory.

@scabug scabug closed this as completed May 18, 2011
@scabug scabug added the build label Apr 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant