Skip to content

Commit 4b97c9b

Browse files
Fix usage of filer/classloader for resources. (#517)
1 parent b88dc13 commit 4b97c9b

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

sdk-api-gen/src/main/java/dev/restate/sdk/gen/FilerTemplateLoader.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,26 @@ public TemplateSource sourceAt(String location) {
3434
return new TemplateSource() {
3535
@Override
3636
public String content(Charset charset) throws IOException {
37-
return filer
38-
.getResource(
39-
StandardLocation.ANNOTATION_PROCESSOR_PATH,
40-
path.getParent().toString().replace('/', '.'),
41-
path.getFileName().toString())
42-
.getCharContent(true)
43-
.toString();
37+
try {
38+
return filer
39+
.getResource(
40+
StandardLocation.ANNOTATION_PROCESSOR_PATH,
41+
path.getParent().toString().replace('/', '.'),
42+
path.getFileName().toString())
43+
.getCharContent(true)
44+
.toString();
45+
} catch (java.lang.IllegalArgumentException | IOException filerException) {
46+
// in vscode/cursor this happens https://github.com/restatedev/sdk-java/issues/516
47+
// so fallback to using the classloader
48+
try (var stream = getClass().getResourceAsStream("/" + location)) {
49+
if (stream == null) {
50+
throw filerException;
51+
}
52+
return new String(stream.readAllBytes(), charset);
53+
} catch (Exception classLoaderException) {
54+
throw filerException; // throw the original exception to retain the original behaviour
55+
}
56+
}
4457
}
4558

4659
@Override

0 commit comments

Comments
 (0)