question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

-Dio.netty.packagePrefix should not be required when shading

See original GitHub issue

Expected behavior

A library may use shading transparently to the user and would be able to be combined with other libraries that also use Netty. Similarly, an application should be able to use shading transparently to the user.

Actual behavior

The shader has to choose whether to rename the native components of epoll and tcnative. If they are renamed, then -Dio.netty.packagePrefix must be set at runtime, which may not be possible programatically. If they aren’t renamed, then epoll and tcnative can fail when mixed with other libraries because: 1) there is a name collision of the META-INF/native/ files in the class path and 2) System.loadLibrary(String) does nothing if it previously loaded a particular name.

Possible fixes

NativeLibraryLoader currently defaults to a package prefix of "":

String name = SystemPropertyUtil.get("io.netty.packagePrefix", "").replace('.', '-') + originalName;

Instead of defaulting to "", I think it should at least attempt to find a package prefix from the class path. There are many options. A sampling:

// Semi-readable implicit
String maybeShaded = NativeLibraryLoader.class.getName();
// Use ! instead of . to avoid shading utilities from modifying the string
String expected = "io!netty!util!internal!NativeLibraryLoader".replace('!', '.');
if (maybeShaded.endsWith(expected)) {
  return maybeShaded.substring(0, maybeShaded.length() - expected.size());
} else {
  throw ...;
}

// Quick and dirty implicit
String name = NativeLibraryLoader.class.getName();
// 42 == "io.netty.util.internal.NativeLibraryLoader".length()
return name.substring(0, name.length() - 42);

// Pre-configured (explicit). User created a file for Netty to read
String resourceName = obfuscateConcat("/META-INF/native/", "io.netty.packagePrefix");
// Could also be a relative, but then users would need to create a file in
// io/netty/util/internal or similar subpackage (I don't see any class in
// io.netty package).
// String resourceName = "packagePrefix";
InputStream is = NativeLibraryLoader.class.getResourceAsStream(resourceName);
if (is == null) {
  return "";
}
return asStringUtf8(is);

In my mind, when shaded, a "" fallback is counter-productive. It gives the appearance that Netty has been properly shaded when in fact it still collides. As a user, I’d much rather epoll and tcnative obviously fail when improperly shaded. So for me an implicit solution has the benefit of failing when misconfigured. But we can mix-and-match behaviors pretty easily.

Depending on the solution, supporting io.netty.packagePrefix may not be necessary any more. An explicit configuration by the user (via io.netty.packagePrefix or similar) may be a necessary supplement to implicit solutions since shading may not use prefixing; io.netty may have been rewritten as a.b or com.example.shadednetty.

I’d be willing to submit a PR for necessary changes, although I’d hope we could agree on an approach first.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ejona86commented, Jul 17, 2017

I’ll send out a PR then using the “Semi-readable implicit” approach then. Truth be told, @normanmaurer, you didn’t slow down the PR at all 😄.

Unless someone says otherwise, I’ll keep io.netty.packagePrefix for the moment to 1) give time for users to try the implicit method and find issues and 2) ease migration from the system property. If things work out and it is redundant then it is easy to remove it in the future.

0reactions
ejona86commented, Jul 17, 2017

@johnou, not really, since there isn’t an explicit API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NativeLibraryLoader xref - Netty
61 } 62 63 WORKDIR = f; 64 logger.debug("-Dio.netty.native.workdir: " + WORKDIR); ... getName(); 105 // Use ! instead of . to avoid...
Read more >
Why has netty of unspecified version shaded into jar?
1 Answer 1 · Thx, i used command mvn dependency:tree to check dependency, then i found the some jar depend io. · Cool,...
Read more >
SHADING SUPPLIES - Zen Linea
Shading supplies - find out which are my favorite supplies for shading Zentangle drawings - comparison of graphite pencils.
Read more >
How to shade & pencil shading techniques | RapidFireArt
Having a full set is not necessary for portrait drawing. The range you need depends on the type of drawings you do.
Read more >
How to Shade with PENCIL for BEGINNERS - YouTube
To shade realistic pencil portraits, here are 3 things you'll need to learn. There are more, but I'll cover them in future videos....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found