influxdata / influxdata/influxdb-java

Support using package-private classes as POJOs for InfluxDBResultMapper

Open
#457 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

difficulty/low kind/enhancement
Dominant language
Java
Stars
1.2k
Forks
469
PR merge metrics
No merged PRs in 30d

Description

I'm using org.influxdb:influxdb-java:2.10.
I'd like to limit my @Measurement classes visibility to package-private, but currently it doesn't work because of the following exception:

org.influxdb.InfluxDBMapperException: java.lang.IllegalAccessException: Class org.influxdb.impl.InfluxDBResultMapper can not access a member of class com.example.MyMeasurement with modifiers "public"

The line which causes this is https://github.com/influxdata/influxdb-java/blob/influxdb-java-2.10/src/main/java/org/influxdb/impl/InfluxDBResultMapper.java#L160.
Looks like it will be enough to replace

object = clazz.newInstance();

with

Constructor<T> defaultConstructor = clazz.getDeclaredConstructor();
defaultConstructor.setAccessible(true);
object = declaredConstructor.newInstance();

If there are no objections, I'll provide a PR.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/main/java/org/influxdb/impl/InfluxDBResultMapper.java at line 160 and trace how measurement objects are instantiated. Verify the behavior with a package-private @Measurement class, and consider a regression test showing that mapping succeeds for this visibility level.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.