Skip to content

Conversation

@pomadchin
Copy link
Member

This PR fixes the read of the nadgrids passed into the proj4 string definition as an external / full path. Bug reported over here: #89 (comment)

I also slightly readjusted the exception definition to pass down the original cause.

The real issue was obfuscated via the exception thrown:

org.locationtech.proj4j.InvalidValueException: Unknown nadgrid: /../proj4j/core/target/test-classes/proj4/nad/100800401.gsb

	at org.locationtech.proj4j.parser.Proj4Parser.parseDatum(Proj4Parser.java:208)
	at org.locationtech.proj4j.parser.Proj4Parser.parse(Proj4Parser.java:50)
	at org.locationtech.proj4j.CRSFactory.createFromParameters(CRSFactory.java:127)
	at org.locationtech.proj4j.CRSFactory.createFromParameters(CRSFactory.java:106)
	at org.locationtech.proj4j.datum.NTV2Test.nadGridExternalTest(NTV2Test.java:89)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:231)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.io.IOException: mark/reset not supported
	at java.base/java.io.InputStream.reset(InputStream.java:741)
	at java.base/java.io.FilterInputStream.reset(FilterInputStream.java:216)
	at org.locationtech.proj4j.datum.Grid.gridinfoInit(Grid.java:350)
	at org.locationtech.proj4j.datum.Grid.mergeGridFile(Grid.java:76)
	at org.locationtech.proj4j.datum.Grid.fromNadGrids(Grid.java:323)
	at org.locationtech.proj4j.parser.Proj4Parser.parseDatum(Proj4Parser.java:206)

@pomadchin
Copy link
Member Author

@robertoricotti could you double check if this fix works for you?

@pomadchin pomadchin mentioned this pull request Jun 15, 2025
// working directory and the classpath (in that order.)
File file = new File(gridName);
if (file.exists()) return new DataInputStream(new FileInputStream(file));
if (file.exists()) return new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the culrprit, apparently only definitions stored in the resources folder were properly loading.

@pomadchin pomadchin added the bug label Jun 15, 2025
@pomadchin pomadchin force-pushed the fix/grid-definition-resolve branch from 1a9df6f to 2991352 Compare June 15, 2025 23:55
@robertoricotti
Copy link

i only have implemented proj4j via gradle, how can i modify it to get this fixed?

@pomadchin
Copy link
Member Author

pomadchin commented Jun 16, 2025

@robertoricotti bascially two ways to test it:

  1. publish locally and add it as a dependency to your project
    • mvn install
      • it's gonna publish jars to the local ~/.m2 folder
    • use it as a dependency in any project
  2. open this project i.e. via IDEA / any other editor and play around with some code

@pomadchin
Copy link
Member Author

I'll cut the release shortly once it's merged in anyways, seem like a mandatory fix anyways.

@robertoricotti
Copy link

robertoricotti commented Jun 16, 2025 via email

@pomadchin pomadchin merged commit ace6185 into master Jun 16, 2025
3 checks passed
@pomadchin pomadchin deleted the fix/grid-definition-resolve branch June 16, 2025 00:37
@robertoricotti
Copy link

robertoricotti commented Jun 16, 2025 via email

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants