lishxi / osmdroid

Automatically exported from code.google.com/p/osmdroid
0 stars 0 forks source link

StackOverflowError around TileWriter.calculateDirectorySize on r865 #188

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Got the following from one of our users, on r865 of osmdroid. Attached is the 
full stack, I snipped out the many repeated lines.

MODEL: MB525
RELEASE: 2.1-update1
BOARD: jordan
BRAND: moto
DEVICE: umts_jordan
DISPLAY: JRDNEM_U3_2.34.1
FINGERPRINT: 
moto/MB525_RTCEE/umts_jordan/jordan:2.1-update1/JRDNEM_U3_2.34.1/89356655:user/r
elease-keys
HOST: zch68lnxdroid07
ID: JRDNEM_U3_2.34.1
PRODUCT: MB525_RTCEE
TAGS: test-keys
TIME: 1288860450000
Thread: Thread[Thread-10,1,main] throwable: 
java.lang.StackOverflowErrorjava.lang.StackOverflowError
        at java.nio.BaseByteBuffer.<init>(BaseByteBuffer.java:28)
        at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:49)
        at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:45)
        at java.nio.ReadWriteHeapByteBuffer.<init>(ReadWriteHeapByteBuffer.java:49)
        at java.nio.BufferFactory.newByteBuffer(BufferFactory.java:51)
        at java.nio.ByteBuffer.allocate(ByteBuffer.java:54)
        at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:351)
        at java.nio.charset.Charset.encode(Charset.java:711)
        at java.lang.String.getBytes(String.java:1022)
        at org.apache.harmony.luni.util.Util.getBytes(Util.java:61)
        at java.io.File.properPath(File.java:1362)
        at java.io.File.isFile(File.java:822)
        at org.osmdroid.tileprovider.modules.TileWriter.calculateDirectorySize(TileWriter.java:150)
        at org.osmdroid.tileprovider.modules.TileWriter.calculateDirectorySize(TileWriter.java:154)
        at org.osmdroid.tileprovider.modules.TileWriter.calculateDirectorySize(TileWriter.java:154)

<snip>

at
org.osmdroid.tileprovider.modules.TileWriter.calculateDirectorySize(TileWrit
er.java:154)
        at
org.osmdroid.tileprovider.modules.TileWriter.calculateDirectorySize(TileWrit
er.java:154)
        at
org.osmdroid.tileprovider.modules.TileWriter.access$0(TileWriter.java:146)
        at
org.osmdroid.tileprovider.modules.TileWriter$1.run(TileWriter.java:52)

Original issue reported on code.google.com by bob.hage...@gmail.com on 22 Mar 2011 at 2:21

Attachments:

GoogleCodeExporter commented 9 years ago
Could you please re-attach the full stack - the one you attached is blank.

And my first guess - the user has a link-loop in their filesystem. Directory A 
has a folder B and in that folder there is a link to Directory A. This causes 
calculateDirectorySize to infinite loop. We should catch this situation if 
possible.

Original comment by kurtzm...@gmail.com on 23 Mar 2011 at 2:05

GoogleCodeExporter commented 9 years ago

Original comment by kurtzm...@gmail.com on 23 Mar 2011 at 2:05

GoogleCodeExporter commented 9 years ago

Original comment by bob.hage...@gmail.com on 23 Mar 2011 at 3:27

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you - that stack certainly looks like an infinite loop. It would be nice 
to confirm if this user had an directory loop because I cannot seem to create a 
symbolic link on my sdcard (even in the emulator).

But assuming it is a directory loop, then this is apparently a problem with no 
easy solution in Java. There is no direct isSymbolicLink() in java.io so the 
best we have is getCanonicalPath(). There are a few implementations that use 
this to implement a isSymbolicLink() such as the one from apache commons (see 
http://stackoverflow.com/questions/813710/java-1-6-determine-symbolic-links).

In our case, what we really need is a way to know if the directory we are about 
to traverse has the same parent root as our current directory. So I think we 
can do something like:

private boolean isSymbolicDirectoryLink(final String aParentCanonicalPath, 
final File aDirectory) {
  try {
   final String canonicalParentPath = aDirectory.getCanonicalFile().getParent();
   return aParentCanonicalPath.equals(canonicalParentPath);
  } catch (IOException e) {
   return false;
  }
 }

Thoughts anyone?

Original comment by kurtzm...@gmail.com on 26 Mar 2011 at 3:07

GoogleCodeExporter commented 9 years ago
Issue 194 has been merged into this issue.

Original comment by neilboyd on 31 Mar 2011 at 2:36

GoogleCodeExporter commented 9 years ago
I am going to commit a solution for this. Please report back and let us know if 
it worked!

Original comment by kurtzm...@gmail.com on 1 Apr 2011 at 12:34

GoogleCodeExporter commented 9 years ago
This issue was updated by revision r910.

Adds symbolic link checking before descending into a new directory in 
calculateDirectorySize

Original comment by kurtzm...@gmail.com on 1 Apr 2011 at 12:34

GoogleCodeExporter commented 9 years ago

Original comment by kurtzm...@gmail.com on 1 Apr 2011 at 12:34

GoogleCodeExporter commented 9 years ago
This issue will be closed. The code has been running for a while and it 
functionally appears to be doing its job.

Original comment by kurtzm...@gmail.com on 3 Jun 2011 at 9:31