Skip to content

Big file issue #514

@cwmccann

Description

@cwmccann

Hi,

I ran into an interesting issue. If the jar files are very large the order of the files (ZipEntries) matter. If the classes come first then they can be found in a scan. If the classes come last they will not be found.

Here's a script and a unit test that shows the issue:

src/test/resources/makeBigJar.sh

#!/usr/bin/env bash

mkdir -p tmp/;
cd tmp;
jar -xf ../record.jar

#ASSET_DIR="zz" # Works
ASSET_DIR="aa" # Doesn't Works

mkdir -p ${ASSET_DIR}
cd ${ASSET_DIR}

for number in {1..23}; do
  echo "Making file ${number}"
  ## make a bunch of big files that won't compress
  dd if=/dev/urandom of="output${number}.bin" bs=1024 count=102400 2> /dev/null
done

cd ..
echo "Building big jar"
jar -cf ../bigjar.jar *

//Copy of the RecordTest
Test src/test/java/io/github/classgraph/issues/BigFileTest.java

public class BigFileTest {
    /** The jar URL. */
    private static final URL jarURL = RecordTest.class.getClassLoader().getResource("bigjar.jar");

    /**
     * Test records (JDK 14+).
     *
     * @throws Exception
     *             the exception
     */
    @Test
    public void recordJar() throws Exception {
        try (ScanResult scanResult = new ClassGraph().overrideClassLoaders(new URLClassLoader(new URL[] { jarURL }))
            .enableAllInfo().scan()) {
            final ClassInfoList classInfoList = scanResult.getAllRecords();
            assertThat(classInfoList).isNotEmpty();
            final ClassInfo classInfo = classInfoList.get(0);
            final FieldInfo fieldInfo = classInfo.getFieldInfo("x");
            assertThat(fieldInfo).isNotNull();
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions